How Multiple slave to single master SPI software slave management works

4.7k Views Asked by At

I am using STM32H7 family of microcontroller as SPI Master Transmit device which needs to talk to 4 SPI slave devices receive only which are also all STM32H7 MCU's. Both master and slave are configured for software slave management. The confusion is how slave will identify when master wants to talk to it or transmit data to it without using hardware NSS pin? How slave device will start receiving in this scenario and stop receiving when all data transmitted?

3

There are 3 best solutions below

1
Codo On BEST ANSWER

If you use software slave select (NSS), you must select and deselect the SPI interface by software.

Typically, you would setup an external interrupt on the pin used as NSS/CS and select/deselect the SPI interface when the interrupt is triggered.

On an STM32F1 chip, the SPI interface is selected/deselected by setting/clearing the SSI bit in the SPI_CR1 register. I assume it's very similar on a STM32H7 chip.

Update

I've just checked the STM32H7 and it's exactly the same.

3
0___________ On

It is very simple. Every slave has one pin called CS. You need to select this device by setting this pin just by using the GPIO. Then you can transmit or receive data. Remember that master has to supply clock even if it wants only to receive data.

1
Junseok Oh On

It seems that the code shown below can manage the problem.

__HAL_SPI_ENABLE(&hspi1);
__HAL_SPI_DISABLE(&hspi1);