Content originally posted in LPCWare by IanB on Sat Apr 12 14:39:21 MST 2014
Thanks. It confirms what I thought . . . and it means that there is a lot of bad software out there! Most SD card projects simply read 1 byte from the card to get the response. No wonder people have trouble with it.
The SD card spec almost seems as though someone had looked at the interface for a SPI EEPROM and said "let's see how complicated we can make this"
I've looked at the linux driver you suggested: it waits for a byte that is not 0xFF, (meaning that the response is in there somewhere) then reads the next byte, (to make sure it has all the response) then shifts it until the bit 15 is zero, which puts the response byte in bits 8-15.
The only snag is that when the data token comes back misaligned, it means that every single byte in the data stream has to be shifted back into alignment . . . which is OK if you have all the time in the world.
I've a week or so to ponder upon this until my prototype pcbs arrive, but I think I'm going to try switching the SPI pins back to GPIO, toggling SCK manually until a zero appears on MISO, then switching back to SPI, and reading a 7-bit word.
Then I have it back in alignment, and I can read the data in as 16-bit words.
It will be sort-of "one-time-use" software, as porting it to any other processor will mean getting all the right GPIO bits.