some SD work other not working custom Arduino shield [SOLVED]

Hello,

Hardware

  • Arduino zero
  • Custom micro sd card holder shield

Setup up

  • Using the SD.h arduino library
  • SCK PIn 13
  • MISO PIn 12
  • MOSI PIn 11
  • SS PIn 10

I have a problem in which i have brought 16, 16Gb Kingston mico SD cards for a project i am working on. For some reason only 4 out of the batch of 16 seem to work i have tested them all on windows machines so the cards do work. I have used the SD.org to reformat the cards with no success.

I made changes to the variant.cpp and variant.h as well as SPI.cpp to allow me to use d10-d13 pins as my SPI port. please see attached files.

The code is failing at return SD.begin(!SS) i have tried the newer SDFAT libary on the quick start sketch and the error codes i get are 0x25 carderror and dataerror 0x1F. However, i can not find the meaning to these error codes any where on the internet ?

Once i have ran the sd.begin i get this signal back from the sd on the MISO. ( see attachment image)

Thanks for reading this!

Ali!

variant.cpp (18.5 KB)

variant.h (7.03 KB)

SPI.cpp (7.07 KB)

SPI.h (4.64 KB)

I don't know, but if all the cards work on your PC, then I would suspect a hardware problem involving the adapter shield. The Zero is a 3.3V device, so that's a proper match to connect directly to the SD card pins. But is the card adequately powered? Do you have a schematic of the shield? Well, I'm just guessing. I have no experience with a Zero.

hello,

I tried this week to get something going however i have not manage to, got in some new 8gb same sd cards but still same problem.

The hardware setup i have for the boards is attached. I am powering it off the 3v3 line from the arduino zero 3.3 pin voltage.

i also tried modding one of the boards as close to the SPI example in the following article article but still had no luck.

looking closely at the scope i see some noise on the MISO line from the power supply line but cannot be sure this is the problem?

Thanks for reads

Ali

It may be that the 3.3V output from the Zero won't handle the extra demand of the SD card. Nominally perhaps it should, but it may not be able to adequately supply any current spikes, such as when you write to the card. Just as a test to see if it makes a difference, you might try powering the SD card from some other 3.3V source, and/or adding significant capacitance to the 3.3V line - 470µF or so.

I don't see any other reason why it wouldn't work, particularly if it works fine with some SDs.

Thanks for the input,

Running off another power supply or adding a 470uf Capacitor didnt seem to do the trick.

Ive had a busy week of working out on the scope where the sd card sequence is failing. Both broken and working cards pass the CMD0 in the sequence returning 0x01. Next up is cmd8 this is where the issue it appears R7 response.

I send it

Cmd8 ( 0x48,0x00,0x00,0x01,0xAA,0x87)

and on the bad cards i receive

R7 (0x00, 0x00,0x00, 0x02, 0x1F)

So first thing i noticed i am not getting the correct check pattern back. i send 0xAA and recieve 0x1F. The 0x02 refers to the Voltage accepted which should be 0x01 for 2.7-3.6volts however in my case its indications "Reserved for Low Voltage Range". * this information can be found from the part1_physical_specification

I think also the first byte of data (R1 response) should be 0x01 indicating that the card is in idle mode (however i am unsure) Looking through the code the SD libary it is only checking for that the Check pattern is the same.

I have now tested on 16 and 8 Gb kingston micro SDHC cards and i have also got a normal micro sd card. All cards have some that pass and other which do not.

The Part1_physical_layer_simplified_specification says i should refer to the low Voltage Interface Addendum however it does not seem to exist.

Any help would be much appreciated

Best Regards

Alister

A while back I wrote an SD card bootloader for the Texas Instruments MSP430 microcontrollers, and I had similar problems, even with some SD cards from the same batch. In the end what worked for me was to follow this procedure to send a command string:

  1. Send an FF. Some cards require another 8 clocks to finish execution of any previous command. I don't know why, but adding this made a difference.

  2. Toggle the CS line OFF, then back ON, waiting a couple mSec after each transition. Again, some cards appear to need this for some reason.

  3. Send the six bytes of the command string.

  4. Send FFs until you receive a non-FF response. Try up to 10 times.

Then as to the commands, after successful CMD0, I continue to send CMD8 until the first non-FF response is either 01 (successful) or 05 (illegal command). If it's an 01, then I send FFs until I receive an AA. If I don't get an 01 or 05, I send CMD8 again.

The sequence after that is pretty complicated depending on whether it is SD or SDHC. I'll attach a flow chart which is the best one I found for getting through the maze. Also, you can look at my code. It's written in MSP430 assembler, but I'm sure you will be able to follow it. Look for the label DoCMD0 and the subroutine SendCommand.

But I'm gonna bet that #1 and #2 above will do it for you.

Hello i fixed this!

The Arduino pins could not provided enough current to drive the sd signal lines due to the SD cards capacitance. Most user who use a custom shield have a chip on there to convert 5v signals to 3v3 which has a power supply meaning the signal are nice and square. However, on my custom hardware i had to enable a register option in the Arduino which let the pin provide more current.

PORT->Group[PORTA].PINCFG[17].bit.DRVSTR = 1; //SET DRVSTR pin

Bit of a weird one,

Thank you

Ali