6 years, 3 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;

    // Select the spi by seting chip select low
    cs = 0;

    // Send some data

    // 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

6 years, 3 months ago.

A few suggestions:

1) try with


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:


  • 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)