1
\$\begingroup\$

I'm trying to roll my own SPI SD card management. So far, I can get the card initialised (details of that further down). Once initialised, when I send the Write_Block (CMD24) or Read_Single_Block (CMD17) commands, the SD card always returns 0x04 (illegal command) as an R1 response. Has anyone seen this before?

Some more detailed information about how I setup the card etc:

  • I send 74 empty bits to the card with CS high,
  • Send CMD0 with CRC 0x95 until I get 0x01 as a response,
  • Send CMD8, argument 0x1AA, with CRC 0x87, and get an R1 response of 0x01, R7 response of 0x1AA,
  • Send CMD55/ACMD41 until I get an R1 response of 0x00

(I've stepped through all these steps with a debugger to check that I'm getting the responses that I expect)

At this point I send CMD17 or CMD24 and get a response of 0x04. I've tried a few different arguments as addresses, 0x00, 0x01, 0x200, but all with the same result. Anyone got any ideas here?

Thanks in advance.

EDIT: I had another kind of timing issue that caused this - my clock was relatively garbled (one very long pulse, and then 7 short ones for each byte), and that seems to have caused the problem (I'm not sure, since I'm still working through other issues). I'm surprised I managed to get the card to initialise at all.

\$\endgroup\$
1
\$\begingroup\$

As a last step of initialization you may want to explicitly set block length to 512 with CMD16 before trying to access the card for read or write.

Edit: as this quick possible fix did not work, let's make deeper troubleshooting:

  1. try another card, better several if you have, to see if any of them work; this way we may able to figure out if issue is related to card or its interoperability with your code;
  2. Check that you send correct CRC for the CMD17/CMD24 command. Illegal command is the response if CRC is wrong;
  3. After CMD17/CMD14 fails, issue CMD13 command to get R2 status - card may be locked or experience ECC errors;
  4. Read OCR register to see if card can operate at voltage you supply (in particular card's memory array, not just its SPI interface and its controller);
  5. I would also read CID and CSD to see what it contains for the card.
\$\endgroup\$
  • 1
    \$\begingroup\$ I will try this tomorrow morning and report back \$\endgroup\$ – Leon Jun 7 '17 at 8:44
  • \$\begingroup\$ This doesn't seem to change anything - I get a 0x00 response from CMD16, then still 0x04 from CMD17 or CMD24. \$\endgroup\$ – Leon Jun 8 '17 at 1:22
  • \$\begingroup\$ @Leon Edited answer. \$\endgroup\$ – Anonymous Jun 8 '17 at 6:59
  • \$\begingroup\$ Hi, thanks a lot for the help so far. I hooked up my setup to a scope and found that my SPI clock was way off (due to various problems with how I've handled timing in software). I'm getting to fixing that and now running into other problems. I may end up closing this post and making a new one, since I think there was a different underlying issue. \$\endgroup\$ – Leon Jun 9 '17 at 7:57
  • \$\begingroup\$ @Leon just add update(s) to the question with your progress. If someone else will be viewing your question, s/he will see what was initial issue, and how you progressed through problem resolution. So, to my understanding, you just shifting wrong command information to the SD-card (due to clock issues), and that's why getting response 0x04. \$\endgroup\$ – Anonymous Jun 9 '17 at 8:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.