Skip to main content
Explorer
July 11, 2023
Question

The first SPI message is weird in SPI slave using DMA

  • July 11, 2023
  • 1 reply
  • 1321 views

This is my code in the SPI slave:

 

#define SPI_PACKET_LEN 8

static uint8_t spiRxBuf[SPI_PACKET_LEN];
static uint8_t spiTxBuf[SPI_PACKET_LEN];

void task()
{
 // spiTxBuf has all zeros, but the master sees "00 00 00 00 FF FF FF FF"
 HAL_SPI_TransmitReceive_DMA(spiHandle, spiTxBuf, spiRxBuf, SPI_PACKET_LEN);
 for (;;)
 {
 if semaphore acquired
 {
 HAL_SPI_TransmitReceive_DMA(spiHandle, spiTxBuf, spiRxBuf, SPI_PACKET_LEN);
 } 
 }
...

 

Only the first 8 bytes is weird. This is the message the master can see for the first message:

 

1600672090.098 TX: FC 00 00 00 00 00 3C 14
1600672090.100 RX: 00 00 00 00 FF FF FF FF

 

When I use "interrupt", the RX are all zeros. Why is that in DMA?

All the rest message are working fine. Only the first RX is weird. I uses only 8 bytes message all the time.

 

    This topic has been closed for replies.

    1 reply

    Graduate II
    July 11, 2023

    Does it need to initialize the buffer before starting to receive data, or maybe discard the first data received?

    YoungKimAuthor
    Explorer
    July 11, 2023

    I can discard the first data. When I try it again, it is all zeros for now. SPI bus can't guarantee the first data?

    Graduate II
    July 12, 2023

    Take a look if there is anything in this post that can be useful for your project:

    https://deepbluembedded.com/how-to-receive-spi-with-stm32-dma-interrupt/

    The "= {0}" is used to initialize the application buffer (but I don't know about the DMA buffer, and also the FIFO buffer, I'm still studying it):

     

    uint8_t RX_Data[1652] = {0};