Skip to main content
SDas.1
Associate II
August 16, 2021
Question

Retrieving multiple SPI packets from DMA

  • August 16, 2021
  • 1 reply
  • 1455 views

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.

    This topic has been closed for replies.

    1 reply

    TDK
    Super User
    August 16, 2021

    > 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?

    "If you feel a post has answered your question, please click ""Accept as Solution""."
    SDas.1
    SDas.1Author
    Associate II
    August 16, 2021

    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

    TDK
    Super User
    August 16, 2021

    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.

    "If you feel a post has answered your question, please click ""Accept as Solution""."