Skip to main content
Explorer
December 23, 2024
Solved

Regarding SPI communication using DMA and manual SPI_CS operation

  • December 23, 2024
  • 2 replies
  • 1290 views

We are performing SPI communication using DMA.

In this case, we manually set the GPIO to High/Low as SPI_CS, but (obviously) SPI_CS goes High before all of the SPI CLK is sent.

How can we manually return SPI_CS to its original state after all of the SPI CLK has been sent?
Should We use SPI_DMATransmitReceiveCplt?

    This topic has been closed for replies.
    Best answer by Saket_Om

    Hello @pass3master 

    1. You need to set the SPI global interrupt in the .ioc.
    2. In your code call HAL_SPI_TransmitReceive_DMA() and then set CS high in the HAL_SPI_TxRxCpltCallback().

    Saket_Om_0-1734964359851.png

     

    2 replies

    Super User
    December 23, 2024

    @pass3master wrote:

    we manually set the GPIO to High/Low as SPI_CS, but (obviously) SPI_CS goes High before all of the SPI CLK is sent.


    No, that's not obvious at all - that's an error in your code!

    When you choose to "manually" control CS, it's up to your code to ensure that it is asserted & released at the appropriate times.

     


    @pass3master wrote:

    Should We use SPI_DMATransmitReceiveCplt?


    That would be the obvious way to do it - as the name suggests, that tells you when the transaction is complete!

    Explorer
    December 23, 2024

    SPI_DMATransmitReceiveCplt is not called. Is there something we need to set? Do we need to set the ioc file?

    Super User
    December 23, 2024

    Have you enabled the interrupt?

    Super User
    December 23, 2024

    You should set CS high in HAL_SPI_TxRxCpltCallback.

    If that's not working, show the relevant code. Ensure DMA interrupts are enabled.