6 years, 4 months ago.

SPI Hello World example not working for Disco l475 iot1

I imported SPI_HelloWorld from link:https://os.mbed.com/teams/mbed_example/code/SPI_HelloWorld/export.

without connecting slave SPI device I tried to add console printfs.I did not see any output on serial console also. Serial terminal settings,baudrate:115200,8N1.

Can some one help. My code*****************

  1. include "mbed.h"
  2. include "PinNames.h"

SPI spi(D11, D12, D13); mosi, miso, sclk Serial pc(USBTX,USBRX,115200); DigitalOut cs(D10); DigitalOut led(LED1);

int main() { pc.printf("Start\n\r"); printf("Start\n\r"); Chip must be deselected cs = 1; led = 0; wait(2); led = 1; Setup the spi for 8 bit data, high steady state clock, second edge capture, with a 1MHz clock rate spi.format(8,3); spi.frequency(1000000);

Select the device by seting chip select low cs = 0;

Send 0x8f, the command to read the WHOAMI register spi.write(0x8F);

Send a dummy byte to receive the contents of the WHOAMI register int whoami = spi.write(0x00); printf("WHOAMI register = 0x%X\n", whoami);

Deselect the device cs = 1; } *****************

2 Answers

6 years, 4 months ago.

I had same issue 2-3 weeks ago. When I change ...

Serial pc(USBTX,USBRX,115200);

int main() {
//.....
}

to...

Serial pc(USBTX,USBRX);

int main() {
      pc.baud(115200);
//.....
}

this wokr for me.

Only tip not solution.

Accepted Answer
6 years, 4 months ago.

You can remove the #include for PinNames.h which is included in mbed.h. You should also use 'pc.printf ()' instead of just 'printf ()' to use the stdio channel to the host . The pc.printf () goes to the serial port with the 115200 baudrate that you have selected. The printf () will use the stderr channel that may still be at the default 9600 baud.