2021-08-16 04:24 PM
Hi guys I have set up my STM32 as an SPI full duplex slave device. All SPI communication happens through DMA. The Master device is a Beaglebone Black communicating over linux spidev driver. The problem I am facing now is if the master sends multiple SPI packets the slave device receives only one interrupt. FYI the HW design does not use any CS line.
I have set up an event based mecahnism using EventHandler from CMSIS RTOS V2 to deal with the SPI communication. Whenever an SPI interrupt occurs it processes the packet and sends back response if needed. But since I am receiving only one interrupt for multiple packets I am not able to distinguish between the different packets and it is overwriting the buffer in a weird manner.
Please suggest me a way on how to deal with this problem. Thanks.
2021-08-16 04:41 PM
> The problem I am facing now is if the master sends multiple SPI packets the slave device receives only one interrupt.
What interrupt is that? You should get RXNE/TXE events for every byte. Or if you're using DMA, you should get an interrupt at half- and full- completion.
If you want to use DMA, you'll need a method beforehand of knowing how many bytes to send/receive. Or you can enable circular mode and poll occasionally for new data.
SPI communication is usually best used with a CS line which allows the two devices to sync up.
> my STM32
Which of the thousands of STM32 part numbers are you using?
2021-08-16 04:46 PM
Hi, thanks for the reply.
To answer your first question I am using the HAL_SPI_TxRxCpltCallback() and HAL_SPI_TransmitReceive_DMA() for the task. So I know before hand the size of the packet and using the same for the transaction.
For your second question I am using STM32G071RB
2021-08-16 04:56 PM
You get one HAL_SPI_TxRxCpltCallback call for each successful HAL_SPI_TransmitReceive_DMA call, at the end of the data transfer. Perhaps the SPI is being clocked before the slave is ready, or another program bug is present.
2021-08-24 02:01 PM
Hi the problem I am facing now is this. If the master is sending multiple SPI packets in one go it gets filled in the SPI buffer. Now when I am trying to do a HAL_SPI_TransmitReceive_DMA() with the size of the first message and then do another call with the size of the second message and so on I am getting interrupt for only the first packet and not the ones following it. Any idea where I am going wrong? Is there a better way to handle multiple packets getting stored in the input buffer at once?