Again really hard to know how you have the hardware setup. That is you have those 4 CS pins, Do you have them with external Pull Up resistors?
If not you need to either do that and/or you may need to make sure that only one of these have a potentially LOW value...
Something like:
Code:
// SPI
#define PIN_SPI_CS_10 10
#define PIN_SPI_CS_9 9
#define PIN_SPI_CS_15 15
#define PIN_SPI_CS_24 24
// Make sure all CS pins are HIGH
pinMode(PIN_SPI_CS_10, OUTPUT); digitalWrite(PIN_SPI_CS_10, HIGH);
pinMode(PIN_SPI_CS_9, OUTPUT); digitalWrite(PIN_SPI_CS_9, HIGH);
pinMode(PIN_SPI_CS_15, OUTPUT); digitalWrite(PIN_SPI_CS_15, HIGH);
pinMode(PIN_SPI_CS_24, OUTPUT); digitalWrite(PIN_SPI_CS_24, HIGH);
// Enable SD card reader
if (SD.begin(BUILTIN_SDCARD)) // Builtin microSD card
{
microSD_Id = 1;
Serial.println("microSD-1");
}
else if (SD.begin(PIN_SPI_CS_24)) // SPI microSD CS on pin 24
{
microSD_Id = 24;
Serial.println("microSD-24");
}
else
{
digitalWrite(PIN_SPI_CS_24, HIGH); // make sure it is not setup to be Active...
if (SD.begin(PIN_SPI_CS_15)) // SPI microSD CS on pin 15
{
microSD_Id = 15;
Serial.println("microSD-15");
}
else
{
digitalWrite(PIN_SPI_CS_15, HIGH); // make sure it is not setup to be Active...
if (SD.begin(PIN_SPI_CS_9)) // SPI microSD CS on pin 9
{
microSD_Id = 9;
Serial.println("microSD-9");
}
...
Again the idea is at most you only want one of these 4 pins to be LOW, and if they are floating, it could easily be random values on what pin might it think it is active on...