I’m trying to add SD card storage to my SBC, bit-banging SPI over a 65C22. I’ve cleared the first hurdle of basic communication with the device, but I’m failing at the second, which is getting the card to initialize. Here’s what I’m doing, in case there are any gotchas that jump out to anyone:
I’m using an Adafruit micro-SD breakout board (
https://www.adafruit.com/product/254). The CD, CS, MISO, and MISO lines are tied to +5 through 10kOhm resistors. CLK, MOSI, and CS are attached bits 0, 1, and 2 of port B on my 65C22; MISO is bit 7.
After 80 clock pulses, I send CMD0 with CS low and get back a 0x01 response, as expected. I send FF with CS high, and then with CS low again, send CMD8 with parameter 0x1AA. I get back 0x01 with the parameter mirrored. So far, so good.
I then start looping, sending CMD55 (with a zero’d parameter block) and then ACMD41 (with bit 20 of the parameter block set, to select the operating voltage). However, even after hundreds of loops, I never any response other than 0x01 (idle). (I’m uncertain if this parameter for ACMD41 matters. I was using a zero block before and it behaved the same way; some online source suggested the parameter issue).
I send an FF with CS held high before each command block is sent.
I’ve tried this with multiple SD cards; they’re all formatted to FAT16, and so limited to 2GB, although they actually have capacities of 16G and 32G. I’ve checked through other people’s code and don’t see any problematic differences from mine; in fact, I extracted the initialization code from Dolo Miah’s code and it seems to have the same results (or lack thereof) as mine. (Further indication that the basic card communication is working is that I get an appropriate response if I send a CMD58 to read the OCR.)
I’m hoping that someone with more experience in this area can make some suggestions for ways I might try to diagnose or resolve this problem!
One thing that struck me is that the effective frequency at which data is being sent and received is around 80kHz. Could it be that that’s just too slow to work with modern cards? Communication seems to be working okay, though, so perhaps I should look somewhere else for the problem?
--p.