cancel
Showing results for 
Search instead for 
Did you mean: 

SPI Communication ( Single Master Multiple Slave)

Ali5
Associate III

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:

Ali5_0-1726036518024.png

1 ACCEPTED SOLUTION

Accepted Solutions
Peter BENSCH
ST Employee

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

In order to give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.

View solution in original post

4 REPLIES 4
Peter BENSCH
ST Employee

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

In order to give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.
Ali5
Associate III

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!

Correct, for parallel access you need separate SPI ports, i.e. separate MOSI, MISO and CLK.

In order to give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.
Ali5
Associate III

I appreciate your response, it helps me a lot.

Thanks again!