Skip to main content
WM_IR
Associate III
May 23, 2021
Solved

HOW TO HANDLE DUMMY DATA FROM SPI

  • May 23, 2021
  • 1 reply
  • 4219 views

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?

This topic has been closed for replies.
Best answer by TDK

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.

1 reply

Tesla DeLorean
Guru
May 23, 2021

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 VenmoUp vote any posts that you find helpful, it shows what's working..
WM_IR
WM_IRAuthor
Associate III
May 23, 2021

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?

TDK
May 23, 2021

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""."