cancel
Showing results for 
Search instead for 
Did you mean: 

SPI readout of a sensor

enrico239955_st
Associate II
Posted on October 12, 2015 at 01:55

Hi,

I am trying a very simple thing: I would like to read a register of a sensor. So the first thing I did is to write the read-register (8 bit) to the sensor. After that the DR register has been filled with dummy data (the data which was on the MISO line while sending the read-register, 0x000000ff).

Next thing is sending dummy data (8 bit) for getting the contents of the sensor. Now the DR register contains 0x00003fff.

For me its not really clear how to read the DR register for clearing its data and to make it free for the next reception.

When is the DR register (containing the data of the RX fifo) cleared?

thanks a lot!
2 REPLIES 2
Posted on October 12, 2015 at 02:20

What STM32 part are we talking about?

For each byte you want to receive you have to send a byte out, the SPI is symmetrical in that regard to generating clock pulses. Each time you read the SPIx->DR it clears the RXNE bit. You have to write SPIx->DR to send another dummy byte.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
enrico239955_st
Associate II
Posted on October 14, 2015 at 18:23

Hi,

I am using the STM32F0. I wonder why the first reception (while sending the read register the STM is already reading the MISO line) will not be cleared after reading DR. While I was debugging I saw the DR register, it contains 0xff after the sending the read register. Some steps further it contains 0x0. After sending the next dummybyte for the reception of the register, the contains 0x3fff. 0x3f is the 8 bit read value of the register. Is it common that the DR register contains a 16 bit value after reading a 8 bit value?