cancel
Showing results for 
Search instead for 
Did you mean: 

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

migmel
Senior

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

1 ACCEPTED SOLUTION

Accepted Solutions
TDK
Guru

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".

View solution in original post

8 REPLIES 8
TDK
Guru

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".

Thank you for your quick reply

I will do it this way...

I have tried but it failed to initialize any of the SD card. Do you think there might be some electrical interference as I connected them directly without adding other electronic component or the problem is more likely to be at a software level ?

TDK
Guru

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".

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.

@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

we dont need to firmware by ourselves, lets talk

That is something I haven't check yet, the MISO tri-state condition. I already could initialize the first SDC by setting CS2 low during initialization process, the problem now looks physical: Sometimes i get FR_NOT_READY, sometimes FR_NO_FILESYSTEM.

Hello, I finally succeeded. You were right about keeping CS of unused SD Cards high. I think the problem was with the SDC adapters. I was using adapters compatible with Arduino and they have this LVC125A chip and a 5V power input(so I had to use a 5V external power source). I replaced them with another adapters non Arduino compatible that don't have the LVC125A chip and have a 3.3 V power input( So I just connected one of them directly to MCU ports) and it worked nicely.

Thank you all for your support