6 years, 9 months ago.

SPI read value stuck on 0 with nucleo L476RG on MBed

The title says it all. I'm stuck with an issue, where all signals are correct on oscillscop, I should be reading the 0x49FC value, but all I get is 0x0000. I'm using MBED, and still cannot read anything else but zero.

Here's an extract of the code I'm using:

/////////////

  1. include "mbed.h"

SPI spiPressure(PC_12,PC_11,PC_10);

spiPressure.format(16,1);

spiPressure.frequency(100000);

spiPressure.lock();

int d1;

d1 = 0;

spiPressure.write(0x0015);

spiPressure.write(0x5540);

while (d1==0)

{

spiPressure.write(W1_CMD);

d1 = spiPressure.write(0);

wait(0.1);

}

printf("!!!! Init OK %d",d1);

//////////////

I tried all the 4 modes, despite the fact that mode 1 seems to be the correct one accordingly to the datasheet of the adressed CI, I tried with and without the lock() feature (there's only one device on that SPI port).

As seen below, the conncected SPI slave is responding correctly, but so far d1 is set to 0.

What am I missing ?

/media/uploads/cthalatoo/pb_spi.png

2 Answers

6 years, 3 months ago.

Christophe, I'm sure you've figured this out by now but if not, then you may have luck using mbed's SPI.transfer() function. It is much more clear in the way it handles the number of bytes written/read and can combine the two operations into one transaction. Good luck!

6 years, 6 months ago.

Hello Christophe, What kind of SPI sensor are you using? Can you attach the datasheet for the SPI sensor? Can you also explain what does this part of the code do?

spiPressure.write(0x0015); spiPressure.write(0x5540);

and this line: spiPressure.write(W1_CMD);

Thank you, Peter, Mbed Team