Skip to main content
Associate III
Dec 23, 2024 9:15 AM UTC
Solved

Regarding SPI communication using DMA and manual SPI_CS operation

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.
Saket_OmBest answer
ST Technical Moderator
Dec 23, 2024 2:39 PM UTC

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

 

In order to give better visibility on the answered topics, please click on 'Best answer' on the reply which solved your issue or answered your question. Saket_Om

7 replies

Andrew Neil
Super User
Dec 23, 2024 9:26 AM UTC

@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!

A complex system that works is invariably found to have evolved from a simple system that worked.A complex system designed from scratch never works and cannot be patched up to make it work.
Associate III
Dec 23, 2024 9:56 AM UTC

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

Andrew Neil
Super User
Dec 23, 2024 10:10 AM UTC

Have you enabled the interrupt?

A complex system that works is invariably found to have evolved from a simple system that worked.A complex system designed from scratch never works and cannot be patched up to make it work.
TDK
Dec 23, 2024 1:17 PM UTC

You should set CS high in HAL_SPI_TxRxCpltCallback.

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

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