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.
7 years, 6 months ago.
SPI example not working on NUCLEO-F411RE
I have set up a very simple spi master example, but looking at the logic analyser there is no spi clock line. So what have I done wrong in the configuration.
#include "mbed.h" #include <stdio.h> SPI spi(D11, D12, D13); // mosi, miso, sclk DigitalOut cs(A2); Serial pc(USBTX, USBRX); // tx, rx int main() { cs = 1; spi.format(8,3); spi.frequency(1000000); // Select the spi by seting chip select low cs = 0; // Send some data spi.write(0xFA); // Send a dummy byte to receive the contents of the WHOAMI register int whoami = spi.write(0x00); pc.printf("WHOAMI register = 0x%X\n", whoami); }
1 Answer
7 years, 6 months ago.
A few suggestions:
1) try with
spi.format(8,0);
do you now see activity on sclk ?
2) review the schematics for your nucleo board and confirm that the SPI port being used is indeed free as some of the port pins are multi-purpose. The port pins for your SPI definition and/or CS may be in conflict due to onboard SB (shorting blocks) of your nucleo board.
For example, D13 = sclk = PA5 on the STM32 CPU port pin but if LD2 is enabled on the same kit then it is PA5 sharing this line via SB21 on the PCB. You may have to remove the shorting block SB21 to allow for sclk to work.
Consider to use for your SPI definition:
SPI spi(SPI_MOSI, SPI_MISO, SPI_SCK); // PA_7, PA_6, PA_5
Any difference ?
Also see here:
https://developer.mbed.org/forum/helloworld/topic/27324/?page=1#comment-52527
- see comment by Kai Lu
If you do NOT use SPI definition but assign D13 as an output digital pin, can you blink LD2 ? (LD2 = D13 = PA5 on CPU)