2020-06-03 12:40 AM
Hi,
I am trying to comunicate raspberry pi (master) and stm32f4 (slave) trough spi with dma. I am using HAL_SPI_TransmitReceive_DMA. The comunication seem is working fine but time to time (when 10/8/6data has been receive/trasnmit +-) my stm32 trasmit/receive worng data and then trasnmit full ceros. After that stm32f4 start to receive and transmit correct data.
Could someone tell me what's going on?
Thanks in advance.
2020-06-03 02:04 AM
How long are the buffers you have allocated for transmission and reception?
And is all the necessary data for transmission available and preloaded into the buffer?
What might be happening is that you are too slow from one DMA-complete interrupt to setting up the next DMA transfer (and with ST's example code it's quite likely that the SPI peripheral and/or DMA channel get shut down and reinitialised as part of the process). As the stm32 is the slave, this can lead to data-overrun if the r-pi tries to communicate during that period.
Suggestions?
Read the reference manual and try to understand how to control the peripheral without going through the HAL libraries.
A circular buffer can be good for reception. But I don't know of a good approach for transmission because you have no control (at the stm32 end) of when the R-Pi will request to transfer the next byte, So what _should_ you transmit if you don't have anything ready to send?
Maybe double-buffering might work (that is where your processing one buffer while the DMA is transferring the other one).
Hope this helps,
Danish