Skip to main content
migmel
Associate III
October 14, 2021
Solved

How to manage chip select pins when reading/writing SD cards on an SPI master/slave(multiple) configuration ?

  • October 14, 2021
  • 2 replies
  • 6441 views

Hello, I have succeeded in accessing (r/w) an SD card with STM32F103C8 blue pill and a microSD adapter using SPI in a master/slave configuration. Now I want to go to the next level by using 2 SD cards in a master / multiple slave configuration.

According to documentation I should have one separate slave select pin (SS or CS) for each SD card and the rest of the pins shared ( VCC, GND, SCLK, MOSI, MISO).

I know how to change CS when working with one slave, now my question is: when there are multiple slaves what should I do with the rest of the CS pins so the do not interfere while working with one card ? Should I keep them always high, always low or should they be changed to the opposite level as the one I am working with?

Thank you guys for your help

    This topic has been closed for replies.
    Best answer by TDK

    CS pins should be kept high and set low only when you want to talk to that specific device. When you’re talking with that device, the CS pins for the other devices should be high.

    2 replies

    TDK
    TDKBest answer
    October 14, 2021

    CS pins should be kept high and set low only when you want to talk to that specific device. When you’re talking with that device, the CS pins for the other devices should be high.

    "If you feel a post has answered your question, please click ""Accept as Solution""."
    migmel
    migmelAuthor
    Associate III
    October 14, 2021

    Thank you for your quick reply

    I will do it this way...

    TDK
    October 15, 2021

    Could be. It could be a lot of things. Although a direct connection between the MCU and the SD card should be fine. SPI pins are driven either by the master or the slave, so pullup/downs are not necessary.

    If you managed to get it to work with a single card, it should also work with multiple cards, assuming you are controlling the CS pins appropriately. If electrical interference isn't a problem for a single card, it shouldn't be an issue when multiple cards are present.

    Be mindful of your connections. If you're using 12" jumper wires, perhaps slow the SD clock speed down to 1 MHz or so.

    "If you feel a post has answered your question, please click ""Accept as Solution""."
    migmel
    migmelAuthor
    Associate III
    October 15, 2021

    0693W00000FCbCDQA1.jpgThank you I will try speeding down the clock. Because after I connect the second SD card, the first one isn't able to initialize anymore even if I keep CS2 high all the time. Separately each SDC work fine.

    Javier1
    Principal
    October 15, 2021

    @migmel​ did you checked if the MISO of the not selected SD card remains high impedance?

    https://hackaday.com/2014/11/25/better-spi-bus-design/

    *neat wiring by the way, very fancy

    hit me up in https://www.linkedin.com/in/javiermuñoz/