In my ESP32 attendance reader, the MFRC522 RFID module and the SD card both sit on the same SPI bus. Everything worked on the bench, then card reads started coming back corrupted.
The cause
SPI devices share MOSI, MISO and SCK, and each one only listens when its own chip-select (CS) pin is pulled low. The SD card's CS handling left MISO asserted, so the reader's data got mixed with the card's.
The fix
- Pull both CS pins HIGH before calling SPI.begin(), so neither device talks during startup.
- Initialise the MFRC522 before the SD card.
- Wrap every SD access in sdBegin() / sdEnd() helpers that assert and release CS in one place.
Lesson: on a shared bus, treat chip-select as a rule you enforce everywhere, not a detail you set once.
