## A microSD puzzle

My board has four SPI ports with common mosi, miso, and sck pins. CS pins are 9, 10, 15, and 24. I can use either the builtin microSD reader or an external reader connected to one of the SPI ports.

The code to initialize the SD card:
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

// 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 if (SD.begin(PIN_SPI_CS_15)) // SPI microSD CS on pin 15
{
microSD_Id = 15;
Serial.println("microSD-15");
}

else if (SD.begin(PIN_SPI_CS_9)) // SPI microSD CS on pin 9
{
microSD_Id = 9;
Serial.println("microSD-9");
}
else if (SD.begin(PIN_SPI_CS_10)) // SPI microSD CS on pin 10
{
microSD_Id = 10;
Serial.println("microSD-10");
}

else // No card
{
microSD_Id = 0;
}

Serial.print("microSD_Id: ");
Serial.println(microSD_Id);```
The puzzle is when the reader is plugged into the CS port 15 or 24, the code reports microSD_Id as the first SPI port in the if block. Rearranging the block will change the reported id. It correctly identifies ports 9 and 10 no matter which order they appear in the if block. The microSD card is read correctly no matter which id has been reported. So my questions are, what's going on here and what will happen if more than one port is connected to peripheral devices?