9 years, 7 months ago.

how to use two SPI in one code?

Hello, i would like to ask how can i use Two spi buses in one code? how to write numbers so i can declare which is SPI 1 and which is SPI 2 bus ?

1 Answer

9 years, 7 months ago.

Have a look at the pinout diagram on the platform page. In your case it looks like you're using the ST Nucleo F401RE. You'll see a few different groups of SPI pins.

In example program you've used it refers to the pins like this...

SPI device(SPI_MOSI, SPI_MISO, SPI_SCK);

SPI_MOSI is an alias for PA_7, SPI_MISO is PA_6, SPI_SCK is PA_5 so if you were to change the line to

SPI device(PA_7, PA_6, PA_5);

it would function the same way.

It means you can also define a second SPI instance using another set of SPI pins, for example you could use.

SPI device2(PB_5, PB_4, PB_3);

Accepted Answer

Are there alias for PB_5, PB_4 and PB_3 as well??

posted by Cristian Fuentes 22 Dec 2015

Does mbed use hardware SPIs in that case or some software imitation?

posted by Pawel Kolodziej 05 May 2017