2022-02-16 11:46 PM
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?
Solved! Go to Solution.
2022-02-17 12:44 AM
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
2022-02-17 12:44 AM
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
2022-02-17 06:46 AM
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.
2022-02-17 07:28 PM
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.
2022-02-17 07:32 PM
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.