3

I'm working on an embedded system that currently only supports SDSC v1 cards. As it's getting harder and harder to find cards less than 2 GB, I'm trying to add support for SDHC cards. The communication with the card is done via the SPI bus.

So here is what I'm doing to initialise the card:

  • Send CMD0. Card returns 0x1
  • Send CMD8 + 0x1AA. Card returns 0x1 and 0x1AA
  • Send ACMD41. Card returns 0x0.

Afterwards, I read the MBR and figured out that there is a FAT16 partition at 0x30 LBA. However, reading a sector from that address (0x30*512) returns a repetition of 0x01 0x09...

  • When sending ACMD41, I'm sending command id 0x69. Is it correct? Or should I send CMD55 and then CMD1?
  • A diagram 1 shows that I need to send CMD58 and possibly CMD16 after sending ACMD41. Is it necessary? I was able to read a valid MBR without doing them.

1. http://elm-chan.org/docs/mmc/mmc_e.html

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
lang2
  • 11,433
  • 18
  • 83
  • 133
  • I would like to mention [this question](http://stackoverflow.com/questions/2365897/initializing-sd-card-in-spi-issues), which is related. I've added some information about voltage selection using ACMD41, which I think is important to know, in order to make your code work with more cards. –  Apr 24 '14 at 15:56

1 Answers1

2

"ACMD" commands all require a CMD55 followed by the relevant command.

For example, for command ACMD41:

SD_command(55, 0, 0, 0, 0, 0xFF);
n= SD_command(41, SD2<<6 , 0, 0, 0, 0xFF);

Don't forget to OR in 0b01000000 to the first argument. The actual command isn't 55, it's 55|0b01000000 (0b01110111, decimal 119). I do it in the SD_command function itself.

Interfacing to SD cards is a HUUUUUGE pain, so don't give up. Good luck!

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Raphael
  • 21
  • 1
  • 2