Recognizing SD Card Problem

I'm using an Arduino Uno, connected to a lcd display and an Adafruit mini SD card reader.
I started out with the example program 'CardInfo" and all worked well.

Then I tried using the example programs for Read/Write (as well as some others) and nothing else worked.
I keep getting errors that no card is present, or that chip select is wrong, etc.
(I am using pin 6 for both the CardInfo and for the others.)

The major program difference seems to be that CardInfo verifies a chip by using and interrogating the statement:
card.init(SPI_HALF_SPEED, 6) [chip select is wired to 6]
while all the others use:
SD.begin(6)

My wiring is somewhat longish and sloppy. (About 6 to 10 inches for some wires.)
I am relatively new to this stuff, and I don't really have a good appreciation of what is actually going on.

My first thought (after exhaustive tests with various software statements) is that the method used in CardInfo is running at a slower speed, and that I am simply lucky that it's slow enough to accommodate my sloppy wiring.

If this is so, I can neaten up things considerably - but at some considerable effort. If the problem lies elsewhere, I'd like to know - and to take a different route so I can just get on with the programming..

Any ideas?

  • Matt

Use shorter wires or make everything half speed.

Thanks for the suggestion.
In the interim I shortened all wires, (max length 2 inches) and put a cap across the power supply leads.
Same result! (Also tried re-assigning and re-wiring the CS pin - same result.)

I think all the wiring is OK.
I don't really understand what the "SD.begin" line actually does.

Any further ideas?

mattbaum:
I don’t really understand what the “SD.begin” line actually does.

The same as how CardInfo starts:

  • Initializes the card into SPI mode (card.init()); it defaults to full speed if not specified.
  • Finds and mounts the first partition with a FAT filesystem (volume.init()).
  • Opens the root directory of the previously mounted filesystem (root.openRoot()).

If any of these steps fail to succeed, then SD.begin() will fail as well. To see better what’s going on, try CardInfo once again; but this time force it to operate at full speed (SPI_FULL_SPEED instead of SPI_HALF_SPEED).

I just tried the suggestion of Lucario448 - with the same result.
Since I first posted this, I have shortened the wires (now about 2 inches max) and added a giant capacitor from +5 to gnd.
I also tried various ports (4, 6, 10 & 17) for Chip Select (each time verifying that CardInfo worked on the port) and ended up with Pin 10. Each time the examples that use SD.begin() fail, while the CardInfo (at either SPI_FULL_SPEED or SPI_HALF_SPEED) works OK.
One other thing I noticed - The CardInfo program lists a lot about the card (type, clusters, blocks, Volume size etc), but does NOT list any files. I thought that this program had previously (months ago, when I first tried it) listed a lot of files on this card.

So I'm still stuck!

4" wires should work fine.

With SD I have to fiddle with connections and make sure the card is formatted FAT32 using an SD formatter, not HD format program. I expect to have to wipe off the contacts if they look dull or got touched but that's about it. There's actually not much to get wrong but of course what there is must be 100% right.

Do you have another formatted SD card with a file on it from your PC? Text file would be best as you could possibly read it and verify it's correct.

Heck, you get card info, IMO the wires should be correct to get that, I'd be looking at that SD card.

mattbaum:
One other thing I noticed - The CardInfo program lists a lot about the card (type, clusters, blocks, Volume size etc), but does NOT list any files. I thought that this program had previously (months ago, when I first tried it) listed a lot of files on this card.

And yet SD.begin() fails.

Looks like it's something before or after opening the root directory; which makes me think that maybe a reformat should fix it. DO NOT USE THE OS UTILITIES FOR THAT!, instead use SDFormatter (or an example sketch that only exists in SdFat).