it took me a while to track this down, so I thought it would be good to share this, in case other people run into similar problems.
The setup is a SD card reader and a LCD display on the SPI bus of an arduino.
The display refreshes (receives data over SPI) every second or so.
SdFat library by Bill Greiman (not the native SD library)
- pull the SD chip select CS pin high (deactivate)
- insert a SD card
(in the meantime, there might be some SPI communicatin to the display)
- pull the display CS pin high (deactivate)
- run the SD.begin function (which will pull the SD chip select pin low by itself)
→ SD card initialisation will fail with the SD errorCode: 0XA,0X1
The problem is that even though the SD CS pin is high, the data on the SPI MOSI bus, which is intended for the display, still somehow confuses the SD card, even before we run SD.begin
The solution is to first stop display activity completely, (no SPI communication),
then insert the SD card
then run the SD.begin function → Success.
After that, switching between SD and display with the help of the CS pins works flawlessly.
Once the SD card is in the above error state, the only way to get it working again is to eject it and re-insert it.
Other things to watch out for:
- the SD.begin function apparently lowers the SPI bus speed, if the initial attempt to talk to the SD fails. Once the initialization process has finally failed, it does not restore the old SPI settings.
Error Code detail:
uint8_t const SD_CARD_ERROR_ACMD41 = 0XA
ACMD41 initialization process timeout
- Arduino Mega
- LC Studio SD card adapter. This one uses resistor voltage dividers, which is not recommended, I know. But I think in this case it is irrelevant, because it was a problem not related to unclean signal edges
- ILI9341 display driver
- Kingston 8GB SDHC Class 4
I hope this might be helpful for someone.