2023-07-10 07:23 PM
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.
2023-07-10 09:29 PM
Does it need to initialize the buffer before starting to receive data, or maybe discard the first data received?
2023-07-10 10:11 PM
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?
2023-07-11 05:06 PM
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):