Important changes to forums and questions
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
10 years, 1 month 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
10 years, 1 month 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);