cancel
Showing results for 
Search instead for 
Did you mean: 

STM32H7 Using SPI with DMA circular mode

CKörn.2
Associate II

Hello,

i currently use SPI interface of my STM32H7B3I board with DMA (mode circular) to build up a connection to Raspberry Zero W (using Python spidev-lib).

At the beginning, I start HAL_SPI_TransmitReceive_DMA() where the data exchange is initialized.

From then it transfers the bytes (8 for now). But from every transmission cycle the RX-Bytes are shifted left on Raspberry RX and right shifted on STM32 RX.

I tried using normal mode but then only one transmission is done and I havent figured out yet how to clear the responding bits manually.

STM32 is slave (full duplex) and Raspberry is master.

Any ideas?

If you need further informations let me now.

Regards

Clemens

6 REPLIES 6

One bit shift? That's hardly related to DMA.

Observe the signals using LA. Check CPOL and CPHA settings on both sides. Make sure NSS goes active (i.e. low) when click is in its idle state.

JW

CKörn.2
Associate II

one byte shift

Then STM32 missed the first frame. How do you synchronize the two devices? Toggle an output pin just after calling the Cube function which starts the communication, and observe it together with the rest of the signals.

JW

CKörn.2
Associate II

I wait for the Raspberry (master) to pull the CS to low. Then I call HAL_SPI_TransmitReceive_DMA().

If I just transmit from STM (Slave) to Raspi (Master) the Communication works and vice versa.

TDK
Guru

You should call HAL_SPI_TransmitReceive_DMA before CS goes low. Otherwise, you need to put a delay between CS going low and the first byte sent in order for the slave to be ready.

If you feel a post has answered your question, please click "Accept as Solution".
CKörn.2
Associate II

Thank you guys.

So I have to add two extra pins that syncs the two devices? Like this:

  1. Raspberry (master) sends an impulse to STM32.
  2. STM32 (slave) waits for raspberry-impulse and calls HAL_SPI_TransmitReceive_DMA when pin is read and sends an impulse back to raspberry.
  3. Raspberry (master) starts sending and reading bytes when receiving the signal from STM32. Like a bilateral rendezvous between realtime tasks.

Further raspberry has to care about error handling.

Or maybe i should switch the raspberry spi-lib :grinning_face_with_sweat: