NEW: Learning electronics? Ask your questions on the new Electronics Questions & Answers site hosted by CircuitLab.
Microcontroller Programming » SD card protocol
January 02, 2011 by Hexorg |
Hey everyone! I'm trying to interface with the SD card via SPI, I found code pbfy0 posted that he used to get a sound the card, but it was a little bit hard to follow, and check sum responses were hard coded. I'm using his base but trying to write a more reusable for future needs code. I'm following the "Part 1 Phisical Layer Simplified Specifications V.2" datasheet that I found somewhere online. Also, the code uses literals like CMD8, which just equals 8. So, the datasheet tells what all kinds of commands and how to do stuff. It says that first you need to send at least 74 clock pulses in order to make sure SD card has enough juice in it. I'm sending spi data using this function
So I just call SPI(0xFF) a few times in a loop. Then I need to set SD card into idle state. I'm sending commads using this function:
After the idle state is issued, we neeed to pull chip-select to low, and issue CMD0 again to put SD card into the SPI mode. after that we need to put the card in idle state again, it doesn't matter what chip-select is, and after that issue a CMD8 - SEND_INTERFACE_CONDITIONS command, with arguments to it being bits 11:8 - a voltage level (set to 0b0001 for 2.7-3.6V), and bits 7..0 is a check pattern that will echo in response. According to the datasheet the response will be "R7" which mostly will echo accepted voltage and check pattern. here's how I check it:
However, when I try to get the responce, It keeps waiting for anything non 0 from the card, unless I tab the connections, then it returns 0xffffffff which is a CRC miss match.... Here is the whole MMC_init():
Could it be my connections? Card is working on computer. |
---|---|
January 02, 2011 by Hexorg |
oh, i forgot to mention that i'm using a voltage divider to get 3.2V VCC for that card. I'm using it this way:
5*(220/(120+220)) = 3.23V, with maximum current of 5/120 = 41.6mA. In the datasheet I found that SD card uses around 15mA most of the time, so I doubt my power supply is any problem. I also use 330 ohm resistors at any input to the card line, like pbfy0 suggested in his post. |
January 02, 2011 by Hexorg |
Ah, well, I found many errors in what I was doing. I'll post a full code here when I finish, but for now maybe someone will know the answer... I initialized the card in spi mode correctly, and set the voltages by CMD8, it even echoed the check pattern and all crc7s are correct. Now i'm trying to set the block size to 24 (this is not a high capacity card so it allows for non-512 block sizes), but in R1 response I keep getting 1, which means card is idle. How do i bring it up from an idle state? |
Please log in to post a reply.
Did you know that many systems in nature can be described by a first order response? Learn more...
|