2024-09-10 11:49 PM - last edited on 2024-09-11 12:25 AM by Peter BENSCH
Dear Community,
I am working on an SPI-based setup where I have one SPI master and four SPI slaves, each connected to the master via their respective Slave Select (SS) lines. The configuration for the SPI master and the chip select lines is set up using SPC5 Studio, with each slave having a separate SPI configuration.
I am using the following function to start SPI communication with each slave:
void spi_lld_start(SPIDriver *spip, SPIConfig *config);
and I'm using this like this
spi_lld_start(&SPID2, &config1);
spi_lld_start(&SPID2, &config2);
spi_lld_start(&SPID2, &config3);
spi_lld_start(&SPID2, &config4);
he challenge arises when I need to start all four SPI slaves simultaneously. Currently, I need to pass a different configuration to this function for each slave. However, when I start one slave, the previous one stops working, as the SPI driver is reconfigured for the new slave.
In my use case, each slave has a watchdog bit that needs to be toggled periodically to keep the slave in normal operation. This necessitates keeping all four slaves active in parallel, but I am unsure how to achieve this with the spi_lld_start function, as it seems to deactivate the previous configuration when a new one is applied.
Is there a way to keep all four slaves running in parallel or to manage the SPI communication in such a way that all slaves remain active? Any guidance or suggestions would be highly appreciated.
Thank you in advance!
Example Setup:
Solved! Go to Solution.
2024-09-11 12:33 AM
SPI can only communicate with one slave at a time. In your example, the select lines SS1, SS2, SS3 each select which slave device you currently want to talk to. You can therefore only talk to the slaves in your example one after the other.
If you want to communicate in parallel via SPI, you must use a corresponding number of SPI ports, i.e. three SPI ports in your example.
Hope that helps?
Regards
/Peter
2024-09-11 12:33 AM
SPI can only communicate with one slave at a time. In your example, the select lines SS1, SS2, SS3 each select which slave device you currently want to talk to. You can therefore only talk to the slaves in your example one after the other.
If you want to communicate in parallel via SPI, you must use a corresponding number of SPI ports, i.e. three SPI ports in your example.
Hope that helps?
Regards
/Peter
2024-09-11 12:36 AM - edited 2024-09-11 12:38 AM
Hi Peter,
Thank you for the detailed explanation, it definitely helps!
Could you please elaborate a little more on this part: "If you want to communicate in parallel via SPI, you must use a corresponding number of SPI ports, i.e. three SPI ports in your example." Are you suggesting that to communicate with multiple SPI devices simultaneously, I would need a separate SPI port for each device (MOSI / MOSI and CLK), or is there another approach I could consider?
Thanks again for your help!
2024-09-11 02:48 AM - edited 2024-09-11 02:48 AM
Correct, for parallel access you need separate SPI ports, i.e. separate MOSI, MISO and CLK.
2024-09-11 02:53 AM
I appreciate your response, it helps me a lot.
Thanks again!