SD card initialization using SPI

I saw a lot of information about MMC / SD cards and I tried to make a library to read it ( Procyon AVRlib change ).

But I have some problems. I am not modifying the original code and have tried here. My problem is initializing the SD card. I have two here: 256 MB and another 1 GB.

I send init commands in this order: CMD0, CMD55, ACMD41, and CMD1.

But the 256MB SD card only returns a 0x01 response for each command. I send CMD1 many times and the 256MB SD card always only returns 0x01 and not 0x00.

1 GB SD is crazier ... CMD0 comes back from 0x01. Nice, but the CMD55 team responds with 0x05. In other cases it responds with 0xC1 and also sometimes responds with 0xF0 with 0x5F in the next intro ...

There is information and examples around the internet, but this is a little confusing. Here in my project I have to use a 1 GB card and I am trying with a microSD card with an SD adapter (I think this is not a problem).

How do I fix this problem?

PS: My problem is similar to the problem in Initializing SD card in SPI problems , but the solution didn't solve my problem. SD card with 1 and nb only returns 0x01 ever ...: cry:

+2


a source to share


4 answers


Why do you need CMD1? And you read the note underneath that says "CMD1 is a valid command for a thin (1.4mm) standard size SD memory card only if used after the card has been reinitialized (not after the power is reset)."?

About the 1 GB card, ideas that come to mind:



  • After every command (send command, get response) are you sending 8 dummy bytes before making CS high?
  • The returned values ​​seem strange (0x05 has no busy bit, so WTF?), Maybe there is a hardware problem?
  • Does the card work otherwise?
+2


a source


Maybe it helps a little: SD Specifications Part 1 Physical Layer Specification



+1


a source


However, the solution may not work for some cards. For these cards, you may need to edit the procedure / library. This may be why your 1 GB card acts differently - it could be a different type of card. The SPI mode of certain cards may not be as popular with commercial equipment and therefore may differ from the specification by some card manufacturers.

If you beat commands and clocks, you can have more control and confidence in the correctness of these procedures. This is helpful because you need a solid foundation to progress gradually. I've found that 80 hours 80 at 80Hz is critical on one card, but can run over 2MHz on another.

Try one command at a time, which is reliable for both cards.

+1


a source


A simple explanation of using MMC / SD over SPI is provided here . I also used a linked FAT filesystem and it works well.

+1


a source







All Articles