1

I'm using an STM32F0Discovery to try and intialize SD Cards via bare metal programming. I have 3 cards that I'm working with. A Kingston 32GB Sd card, SanDisk Ultra 32GB sd card, and a Transcend 1GB sd card. Right now, only the Transcend SD card can get past CMD0. The other two SDHC cards return 0xff.

Do SD and SDHC differ someway?

Anyone know why my code would work for an SD card and not an SDHC card?

The spi clock speed is set to 375kHz which is in the 100-400kHz range.

Intialization steps

I start by setting the CS line high and sending 0xff 20 times (overkill ik). Set CS low, and send CMD0, wait 100ms, then check for response 1.

My send CMD function involves first sending a 0xff then the cmd|0x40, and then the cmd argument then teh crc. For CMD 0 this is (cmd|0x40), the argument 1 byte at a time, then the (crc|0x01) which is 0x95|0x01. Response1 invoves sending 0xff 8 times or untill 0x01 is returned, whichever comes first.

the whole cmd0 r1 code is in a do while loop, waiting until R1 returns 0x01. cslow, cmd0, r1, cshigh

After sending CMD0 and checking for Response 1. For my 1gb SD card i get an 0x01 response, but form my two SDHC cards I get an 0xff.

I tried looking it up, but it seems like most people are able to get past CMD0.

I saw This response to a similar issue, where someone mentioned when writing a command, send 0xff untill you get 0xff, but it didn't work. I also saw one mentioning that when an SD card has been initialized that cmd0 won't return 0x01. I've been in debug mode so I would start the program, remove the sd card and put it back in and then go through the process.

I have a break point after response1

I'm quite lost on what to try and do.

voidcat
  • 11
  • 1
  • SDHC IIRC may or may not have SPI support (it's not obligatory by the specifications). Take real hardware that has SDHCI controller (anything with Intel or many ARM SoCs have it). – 0andriy Feb 13 '23 at 09:00
  • @0andriy. So I looked up the datasheet and talked to support, and they each said it follows sda protocol and can communicate with spi. I'll look into the SDHCI controller thing, but the cards do work on my computer – voidcat Feb 13 '23 at 18:05

0 Answers0