cancel
Showing results for 
Search instead for 
Did you mean: 

Can STM32F4 communicate with multiple spi slave devices parallely?

SMika.1
Associate II

Hi,

I'm trying to communicate with multiple spi slave sensors using STM32F401.

I need to access the sensors many times in 1ms period, so I want to drive SPI1 and SPI2 in parallel.

I set SPI1 and SPI2 to use DMA, then called, HAL_SPI_TransmitReceive_DMA function with SPI1 then with SPI2.

My expectation was SPI1 sclk and SPI2 sclk signal would output almost simultaneously, but result was not like that.

During SPI1 sclk outputting, SPI2 sclk line is silent. After SPI1 sclk output finished, SPI2 sclk started.

Can I realize SPI1 and SPI2 output in parallel?

1 ACCEPTED SOLUTION

Accepted Solutions
KnarfB
Principal III

You probably experience only the delay caused by the HAL_SPI_TransmitReceive_DMA software. The hardware is able to run simultaneously. Prepare the registers of both interfaces, but don't enable them. When ready, enable both SPI interfaces. Best done at register level, maybe LL.

More advanced: trigger DMA transfer by a timer: https://community.st.com/s/question/0D50X0000C4MPwQSQW/trigger-spi-dma-transfer-from-timer-directly

hth

KnarfB

View solution in original post

4 REPLIES 4
KnarfB
Principal III

You probably experience only the delay caused by the HAL_SPI_TransmitReceive_DMA software. The hardware is able to run simultaneously. Prepare the registers of both interfaces, but don't enable them. When ready, enable both SPI interfaces. Best done at register level, maybe LL.

More advanced: trigger DMA transfer by a timer: https://community.st.com/s/question/0D50X0000C4MPwQSQW/trigger-spi-dma-transfer-from-timer-directly

hth

KnarfB

TDK
Guru

They can't be triggered at the exact same time. You could set one of them in slave mode and use the clock from the master SPI as the slave's clock to sync them.

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

Thank you KnarfB.

I tried again, and I found both SPI can output sclk simultaneusly with 5usec delay, as you commented.

In my application, one transmit transaction spends 4usec, so, I couldn't notice two SPI worked in parallel. ​

Thank you TDK.

I think your idea is good. Unfortunately, my pcb board doesn't have connection between two SPI pins.

I'll try in future.