cancel
Showing results for 
Search instead for 
Did you mean: 

HOW TO HANDLE DUMMY DATA FROM SPI

WM_IR
Senior

0693W00000AO3oRQAT.pngHi, I would like to ask, I have a SPI setup Full duplex which my STM32f302R8 nucleo board as a master and arduino UNO as my slave.

I send a data 0x0C from master to slave. During transmission, I know that the slave will return a dummy data back to the master.

So, I would like to ask, let say I want the slave to send data 0xF5. How do I handle the dummy data that is sent back during data transmission from master to slave? In order I want to make sure the master will only receive the real data which is 0xF5 from slave.

Example: Master send 0x0C to Slave. Then, slave return dummy data also 0x0C during data transmission. Then, the slave will send 0xF5. So, how do we handle the dummy data before the master receive the true data which is 0xF5?

1 ACCEPTED SOLUTION

Accepted Solutions

Yes, but be aware the FIFO is small and you'll need to read things as they come in rather than waiting for the entire message to be received in order to avoid a FIFO overflow error.

If you're using HAL, HAL_SPI_TransmitReceive will do this.

If you feel a post has answered your question, please click "Accept as Solution".

View solution in original post

6 REPLIES 6

You'd ignore it or throw it away.

If in a buffer, you skip the dummy byte

So if you expect to get 6 bytes of valid data, you'd use a 7-byte array, and then copy 6 bytes from &buf[1]

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

Im a little bit confused, when the master sends a data, there will be a returned dummy data that will be collected in the Rx buffer right? So, if we skip the dummy data, does that will cause our Rx buffer still also store the dummy data? Do we need to do the dummy read for the dummy data first? to clear the Rx buffer?

Yes, you need to read it to clear the RXFIFO and access later bytes, and to avoid overrun errors.

If you feel a post has answered your question, please click "Accept as Solution".

So, I have a situation where I send letter "hello" string which is 5 bytes from master to slave. So what happen is during the data transmission, the Slave will return back "hello" as a dummy byte. But, the real data that I want to receive is 0xF5 after the dummy data is sent.

What I found is before I receive the real data, I need to do the dummy read 5 times because of 5 bytes returned dummy data. Then, I can received the real data.

So, this issue makes me think how about when I send a sentence let say "I love STM32", every letter that I sent, I need to do dummy read before receiving the real data.

In case of sentence "I love STM32", the total size is 12 bytes, So, I need to do dummy read 12 times before receiving the real data. Is my concept is true?

Yes, but be aware the FIFO is small and you'll need to read things as they come in rather than waiting for the entire message to be received in order to avoid a FIFO overflow error.

If you're using HAL, HAL_SPI_TransmitReceive will do this.

If you feel a post has answered your question, please click "Accept as Solution".

ahh.. I see. there is a function HAL_SPI_TransmitReceive, Thank you for clearing my doubts. Im right now trying to understand the SPI behaviour from scratch by developing the SPI driver.