2019-10-31 11:33 PM
Hello,
I need to connect more than 2 MCUs with SPI connection(1 Master, 2Slaves). Here is my Hardware connections :
MISO1->MOSI2 && MOSI3
MOSI1->MISO2 && MISO3
SCK1->SCK2 && SCK3
NSS1->NSS2 && NSS3
But I don't know how I can select each slave with master (MCU1). Is there any SPI chip select available in the MCU or it i desired?
Solved! Go to Solution.
2019-11-01 05:56 AM
If you have 2 slaves and it's a multi-drop bus, use 2 GPIOs on the master side and connect each one of them to the NSS of each slave.
Then you can use the HW NSS SPI function on slave side to disconnect MISO when NSS is high (unselected).
In my projects, I used a different scheme to have up to 12 SPI slaves with 6 pins in multidrop mode. This is another story, although all works fine without NSS HW setup, I use NSS as EXTI interrupt to disable MISO pin and it's working fine, while having the HW NSS option as fallback.
2019-10-31 11:39 PM
Take out the NSS line. The hardware NSS signal is not useful.
Instead, hook up two CS lines as general GPIO pins from the master to slave. One line per slave. Hold those high by default and select a slave by pulling that line low during communication.
2019-11-01 12:02 AM
If you have only 1 master and 1 slave, it's point to point, so yes, you don't need to bother with NSS on the slave side to put tristate MISO by NSS high level.
2019-11-01 12:04 AM
I really appreciate your explanation.
In the software, how can I implement this chip select pin? it means if the line is high I should ignore the incoming packets or there is another approach to implement in SPI software and it configures the software the CS pins.
2019-11-01 12:18 AM
Thank you for you comment.
In the 1master and 2 clients configuration should I use NSS pin?
2019-11-01 05:56 AM
If you have 2 slaves and it's a multi-drop bus, use 2 GPIOs on the master side and connect each one of them to the NSS of each slave.
Then you can use the HW NSS SPI function on slave side to disconnect MISO when NSS is high (unselected).
In my projects, I used a different scheme to have up to 12 SPI slaves with 6 pins in multidrop mode. This is another story, although all works fine without NSS HW setup, I use NSS as EXTI interrupt to disable MISO pin and it's working fine, while having the HW NSS option as fallback.