On Thu, Aug 18, 2011 at 5:01 AM, IVP wrote: > Hi all, > > having the dickens of a job initialising a 4GB SDHC card. Unknown > manufacturer. And probably won't find out until I can read the card's > registers > > The procedure is, from what I read, > > Send > 74 clocks with /CS high and DI high > Send CMD0 > Send CMD8 > Send CMD55 + ACMD41, repeat until response =3D 0 > > Here's my results > > http://home.clear.net.nz/pages/joecolquitt/sdhc.html > > This procedure seems to be the one that generates the most "can't > get it to work" posts and the replies aren't consistent. Some say turn > this bit on, turn that bit off, repeat this bit, don't repeat etc etc > > My reading includes > > http://elm-chan.org/docs/mmc/mmc_e.html > > which is referred to often, but IMVHO has inconsistencies with > the official SD spec pdfs he links to > > Also tried the MChip forums, AVRfreaks and others > > I'm at a loss to see why the card doesn't come out of initialisation > so I can move on to the next steps in the flow charts > > More exact diagrams would be really really helpful. They say so > much more than lines and lines of geek speak > > Any suggestions ? > > TIA > > Joe My procedure, worked on most cards last time I messed around with it. SD cards are my least favorite peripherals to interface with because they are sort-of documented (mostly) and it should probably work. Get what I'm saying? ------------------------ Notes on SD card initialization for SPI mode: 1. SPI is low speed on startup of SD card 2. Turn power on for SD card 3. Card requires 74+ cycles to initialize; send dummy bytes to toggle clock 4. Issue command: GO_IDLE_STATE (CMD0) while holding CS LOW Precalculated CRC-7 for this command: 0x95 Get response R1: 0b00000001 [no errors, enter idle mode] If response is >1 then RETRY; goto 4 5. Issue command SEND_IF_COND (CMD8) to check if this is ver 1/MMC or ver2 HC card. precalculated CRC-7 for this command: 0x87 get R1 response (1 byte) check idle bit: if idle bit is clear then card is not HC else card gave affirmative response to CMD8. It should be sending 32 bits of info with lower 12 bits =3D 0x1AA 6. If data from #5 ended in 0x1AA then card is V2 Else card is not V2. 7. Issue command ACMD41. From this point on, CRC is NOT NECESSARY because you are in SPI mode. Aka: CMD55 + CMD41 get R1 response send SEND_OP_COND command (Start card initialization) get R1 response check R1_IDLE_STATE_BIT if set then goto 7 (repeat #7 until out of idle state) 8. Set block size to 512 bytes send SET_BLOCKLEN command get R1 response 9. Read OCR and check CCS (bit 30) Aka CMD58 send READ_OCR command get R1 response Get 32 bit R3 response If bit 30 of response is set then card is SDHC 10. Read bytes from card until returned byte is 0xFF. Indicates card is idl= e. .... Card is now ready (maybe) I left out some error checking. You need to flash the CS* line before each new command. --=20 Martin K. --=20 http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist .