Search This Blog

Wednesday, March 24, 2010

SD Card Working Notes

EDIT: I've seen a lot of people hit this post.  Ignore it.  It is rubish and random ramblings.  See this post for stuff that works: http://thelast16bits.blogspot.com/2011/11/micro-sd-card-low-level-io.html

This is an incoherent blog to capture some notes in progress.  I'm trying to figure out how to connect a PIC to an Sd card ( MMC, SD or high capacity SD ).  I'll be working with a 2GB micro SD card.  Just in case of hard drive crash, here are my notes so far:

What we have so far:
1. polynomial for crc7 is 10001001
2. The only commands for which we need a valid crc7 are cmd0 and cmd8.
   Spi mode ignores crc for all others unless you are stupid enough to enable it.
3. If you make the check byte 0x22 for cmd8, you will have the same valid crc as for cmd0,
   value = 0x95
4. TODO - It seems that acmd command value should be 0x40 + 41 = 0x69, but
          one website reports that the value should be 0xc0 + 41 = 0xE9.  The problem
          is that this would require setting the start bit to one.  Not sure this is right.
5. Need to adjust code to take in 5 bytes for response R7 from cmd8
6. Need to figure out if CS is high or low when pulsing for response.  The web seems to say
   that that you let it go high to read. 
7. Need to figure out if we need the dummy byte that ELF talks about.
8. Adjust messages to post to PC instead of LCD for now.  I need all the data I can read!
9. cmd55 precedes all acmd41 calls and gets R1 back.  hex = 0x77 bin = 0b01110111

0x95 =     10010101
cmd0 =     01000000
cmd8 =     01001000
cmd55=   
acmd41=    01101001
CMD0    01000000 00000000 00000000 00000000 00000000 10010101
CMD8    01001000 00000000 00000000 00000001 00100010 10010101
CMD55    01110111 00000000 00000000 00000000 00000000 10010101
ACMD41    01101001 01000000 00000000 00000000 00000000 10010101


GOT IT!
    0X22 IS THE CHECK VALUE THAT WILL MAKE CMD8'S CRC 0X95!!!
cmd8 = 0b01001000
twenty = 00000000000000000000
voltage = 0001   ( for 2.5 - 3.3 Volts )
check = 00100010 ( 0x22 )
0x4800000122   binary = 0b100100000000000000000000000000100100010
cmd 55 = 0x77
acmd41 = 0x69

;  polynomial for crc7 = 10001001
;  crc for cmd8 should be: 11010101 ( 0xD5 ) when voltage set to 0b0001 for 2.5 - 3.3 V
;  crc for cmd8 could be:  11000011 ( 0xC3 ) with no voltage specified
;  need crc for cmd8 with check value of 0x1AA...
;  NOT RIGHT -- message = 4800000001aa   crc = 0x95 10010101  - so that's why they use AA...
;  found this for command byte of ACMD41: The ACMD41 is not 0x40 + 41 but 0xc0 + 41
;  So, 0xc0 + 41 = 0xE9... maybe...
;  crc for cmd0 is:        10010101 ( 0x95 ) this is per the physical spec
;  cmd55 is 0bb1110111
;  acmd41 is 0b11101001  - The one in bit eight ( 'sposed to always be zero ) bothers me.

No comments:

Post a Comment