Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Initialization of a microSD card using an SPI interface

I'm using a microSD card in an embedded design. The card is connected to a microcontroller using the SPI interface. It worked fine for all cards I've used before, but now my new card will not initialize. The card is a Transcend 2 GB microSD card (TS2GUSD).

After sending the initial clock train to switch to SPI mode, I do the following:

  1. CMD0 (Argument 0, CRC 0x95) -> Response 0x01 -> OK

  2. CMD8 (Argument 0x000001AA, CRC 0x87) -> Response 0x01 0x000001AA -> Means it's SDC V2+ card, the voltage range 2.7 V - 3.6 V is supported -> OK

Then I should send the ACMD41 command, but when sending the CMD55 (argument 0, CRC 0) that must precede CMD41, I get response 0x05 -> Illegal Command. I've also tried to send CMD1 (for MMC cards), but it gives a similar illegal command response. The code works fine with my Sandisk 2 GB microSD card.

How do I fix this problem?

like image 406
Ron Avatar asked Jun 05 '09 12:06

Ron


People also ask

What is SPI mode for SD card?

The SPI mode is an alternative operating mode that is defined to use the MMC/SD cards on microcontrollers without a native host interface. The MMC/SD can be used on a microcontroller via a generic SPI interface or some GPIO ports. Therefore, the SPI mode is suitable for low cost embedded applications.

Do SD cards use SPI?

SD cards use the Serial Peripheral Interface (SPI) protocol to communicate with microcontrollers and other computers. SPI is a synchronous serial protocol that supports two-way communication between a controller device such as a microcontroller and a peripheral device like an SD card reader.

What interface does an SD card use?

SD card has a native host interface apart from the SPI mode for communicating with master devices. The native interface uses four lines for data transfer where the microcontroller has SD card controller module and it needs separate license to use it.


1 Answers

I seem to have found the issue. When I calculate the correct CRC for CMD55 and send that instead of a dummy CRC, the command is accepted (result 0x01). If you look at the physical layer specification in section 7.2.2, it explicitly says that:

The SPI interface is initialized in the CRC OFF mode in default. (except for commands CMD0 and CMD8).

This doesn't seem to be the case with this series of Transcend cards, thus violating the specification. Also in case of a CRC error the reply should be 0x09 instead of 0x05. I've tried to explicitly turn off CRC checking with CMD59, but that doesn't seem to help.

=> Calculating the correct CRC for (all?) commands makes the card work.

I'm in contact with Transcend support about this. If I learn something useful I'll you know here.

Note that I used other 2 GB Transcend cards before, but they were made in Taiwan, while the new one is made in Korea (and seems to be a Samsung card (MMAGR02GUDCA)).

like image 60
Ron Avatar answered Sep 28 '22 00:09

Ron