0
\$\begingroup\$

I am trying to read an microSD card through an unbranded SD slot and a Basys3 FPGA. The microSD card, Kingston microSD HC 8GB Class 4, is used via an SD card adapter, also Kingston.

I am having trouble with getting past CMD8 of the initialization process. After I sent CMD0 it responded with 0x01 which is normal. After CMD0 I sent the CMD8 command; it responded with 0x000000021F. I wasn't able to find anything related to this code in any documentation.

To test, I tried using a SanDisk Ultra SDHC 32GB Class 10 with the same code. It successfully initialized.

Other things I have tried:

Please help.

Waveforms

The first one shows all of the initialization process. SD_CD is Card Detect (Active Low) and SD_WP is Write Protect (Active Low). SD_CLK is running at 390 kHz, 256 times slower than _cpuClock. Please note that the SD_MISO, SD_CD, SD_WP and _cpuClock are all simulated manually (i.e. doesn't receive any signal from the SD module). After card is detected, 1 millisecond is waited, followed by 74 SD_CLK's.

enter image description here

The second image is a zoom in of CMD0 and its response.

enter image description here

The third image is a zoom in of CMD8 and its response.

enter image description here

The final image is a zoom in of CMD55 and its response.

enter image description here

Update 1 (Prior to @Annoymous Answer) I managed to get my hands on a couple more cards. After testing it seems that only SanDisk Class 10 SDHC (both SD and microSD) returns an initialization finished state. The Kingston Class 4 SDHC SD returns a timeout after CMD0 while the Kingston Class 4 SDHC microSD returns a 0x000000021F. Changing the adapter made no difference in all cases. In the image below, the successful ones are in green and the unsuccessful ones are in red.

enter image description here

Update 2 (Response to @Annoymous Answer) After changing MOSI from posedge to negedge, the Kingston Class 4 SD card seems to initialized (which was previously timeouted). However, the Kingston Class 4 microSD card still respondsed with 0x000000021F.

\$\endgroup\$
  • 1
    \$\begingroup\$ Both are SDHC, right? Are they both capable of the same class of operation? Sounds like the adapter is the difference. Any other adapters handy? \$\endgroup\$ – jonk May 21 '17 at 20:49
  • 1
    \$\begingroup\$ Do you send enough dummy clocks prior to initialization? \$\endgroup\$ – JimmyB May 21 '17 at 21:00
  • 1
    \$\begingroup\$ @JimmyB I sent 74 clocks prior to initialization. I will update my answer with the simulated waveform. \$\endgroup\$ – krismath May 21 '17 at 21:04
  • \$\begingroup\$ @jonk I updated the class of each of the cards. Does class effects operation? I know that there are SDv1 and SDv2, but I am not aware how this is related to Class 4/Class 10. Regarding your other question, no other adapters are available. \$\endgroup\$ – krismath May 22 '17 at 11:26
  • 1
    \$\begingroup\$ @krismath I wish I were expert in any of this, but unfortunately I'm not. You probably know a fair bit more than I do. But sometimes it helps to hear someone else's thoughts and questions when tracking something like this, so I offered a few that came to mind. That's about my limit, though, without spending a lot more time getting up to speed. \$\endgroup\$ – jonk May 22 '17 at 17:52
3
\$\begingroup\$

Attached CMD8 picture shows normal response 1AA (2.7 - 3.6 V, and check pattern AA).

Several notes on things I see:

  • do not start command immediately after you activate CS. Wait 8 spare clock cycles, and only then start the command;
  • same at the end. Do not deactivate CS just after you think you got complete response for the command. Perform 8 more spare clock cycles before you deactivate CS;
  • I am not sure but pictures show that you put data onto the SD-card inputs on positive edge of the SD-card clock. As I recall SD-card latches data on positive edge of its clock, thus putting data there at the same time may violate timing. In my implementation, if I recall properly, I put data onto SD-card input lines on negedge, so that it samples it on next posedge.
\$\endgroup\$
  • \$\begingroup\$ Actually the CMD8 response was manually simulated -- this wasn't the actual SD's response. I will try what you suggested. Thanks! \$\endgroup\$ – krismath May 22 '17 at 9:53
  • 1
    \$\begingroup\$ Thanks, more cards seems to have initialized after posedge is set to negedge. More dummy clocks are next in list! \$\endgroup\$ – krismath May 22 '17 at 11:56
  • \$\begingroup\$ Unfortunately, after giving it more dummy clocks and setting CS according to you answer, the SD card still responds with 0x000000021F \$\endgroup\$ – krismath May 22 '17 at 18:48
  • \$\begingroup\$ Ok, then I would do the following: (1) did you check if this card is operational at all? Try it with windows or linux machine. I do not see it from your post; (2) take either real waveforms from the SD-card interface, or perform simulation to see the waveforms and timing of them towards the card. \$\endgroup\$ – Anonymous May 22 '17 at 19:07
  • 1
    \$\begingroup\$ It seems that while the 'faulty' card is operational on a standard, commercial microSD card reader, the card failed to operate in my situation. I am clueless and would probably leave it at that; however if anybody is interested in the code, please feel free to visit github.com/kkalavantavanich/SD2017 . \$\endgroup\$ – krismath Jun 7 '17 at 18:28

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.