sdcard.py - OSError: timeout waiting for response
I am using 8 GB microSD card, format FAT32. During mount code detects it as v2 card, but gives "OSError: timeout waiting for response". Tried to format as 4 GB FAT, did not work.
Raspberry Pi Pico
Pico: sdcard.py timeout waiting for response
I was unable to use the https://github.com/micropython/micropython/blob/master/drivers/sdcard/sdcard.py code as-is on my Raspberry Pi Pico, I would get "timeout waiting for response" when accessing my microSD card device, I presume from this part of the code:
# read until start byte (0xff)
for i in range(_CMD_TIMEOUT):
self.spi.readinto(self.tokenbuf, 0xFF)
if self.tokenbuf[0] == _TOKEN_DATA:
break
else:
self.cs(1)
raise OSError("timeout waiting for response")
I was able to fix this by simply changing the _CMD_TIMEOUT from 100 to 1000:
_CMD_TIMEOUT = const(1000)
I don't know if the Pico board is faster, or my old SanDisk 8GB is slower than what was tested, but there is an existence proof that more cards will work with a longer timeout. Also, another Pico user with other SanDisk uSD cards reported the same problem, and found the same fix worked for them as well: https://www.raspberrypi.org/forums/viewtopic.php?f=146&t=308819&start=25