Skip to main content
Visitor II
November 1, 2019
Solved

SPI chip select pin

  • November 1, 2019
  • 5 replies
  • 2852 views

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?

    This topic has been closed for replies.
    Best answer by S.Ma

    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.

    5 replies

    Super User
    November 1, 2019

    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.

    Visitor II
    November 1, 2019

    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.

    parisaAuthor
    Visitor II
    November 1, 2019

    Thank you for you comment.

    In the 1master and 2 clients configuration should I use NSS pin?

    parisaAuthor
    Visitor II
    November 1, 2019

    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.

    S.MaAnswer
    Visitor II
    November 1, 2019

    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.

    Visitor II
    February 26, 2025

    Hi

    Were you able to do this? Can you please help me :folded_hands:. Can you please share me the code or atleast the connections you implemented on the controllers? 

     

    STM is so confusing and difficult. The useful resources are very low in STM32