Yet another SD initialization fail...

I see a lot of discussion of this, but I've tried most of the suggestions and am still having no luck getting my SD card off the ground. Any help much appreciated!

I have an Arduino Mega 2560 R3, with an SD/microSD board from http://yourduino.com/sunshop2/index.php?l=product_detail&p=246

It's wired as:

#define SS 53
#define MOSI 51
#define MISO 50
#define CLK 52
#define CS 4

it has power (has an power LED, which is a nice touch).

It has a 2GB card in it, freshly formatted by the app from sdcard.org. Mac OS X disk utility says:

Mount Point : /Volumes/CANON_DC Capacity : 2.05 GB (2,045,121,024 Bytes)
Format : MS-DOS (FAT16) Available : 2.04 GB (2,042,167,296 Bytes)
Owners Enabled : No Used : 2.7 MB (2,686,976 Bytes)
Number of Folders : 0 Number of Files : 512

I'm working from the SD.h based sketch available at http://arduino.cc/en/Tutorial/ReadWrite

But I always get 0 (fail) back from:

SD.begin(CS);

I've tried swapping 50 and 51 too; and using pinmode() to set 53 and/or 4 to output. There's no Ethernet device in sight. I do have a low-side switch hanging off pin 10, so I'd have to move that before I could freely set 10 high; but from what I've read, SD on a Mega shouldn't care about pins 10-13 at all.

Any ideas?

Thanks!!!

Steve

Try running the CardInfo example. Do not modify the example, it will use the correct SPI pins on Mega and by default used pin 4 for chip select.

This line is not needed but shouldn't cause a problem. It is best to just remove it rather than edit it for Mega.

  pinMode(10, OUTPUT);     // change this to 53 on a mega

You have a hardware/wiring problem if the example prints:

"initialization failed. Things to check:"

If the example prints this, you need to format the card:

Could not find FAT16/FAT32 partition.

Do not use the Mac format utility, it does not follow the SD standard and sometimes even uses GPT style partitions.

Use the SD Formatter utility from the SD Association.

@sderose, you're new to Arduino, and wouldn't imagine it, but the Arduino environment has tons and tons of bugs all over the place. That's why there are over 2,000,00 posts on this forum.

Bill didn't specifically mention it, but the SD library that comes with the Arduino IDE is 5 years out of date. You'd think the sketches might work properly even so, I mean for crying out loud, people have been using them for 5 years! However, the "Cardinfo" sketch only works part-way on my Arduino [ie, it hangs when trying to run the "root.ls(LS_R | LS_DATE | LS_SIZE);" line], and the "Files" sketch, which creates and removes a file, ate my SD card a couple of days ago. OTOH, the "listfiles" example sketch works fine for me.

After running "Files", the card was unusable on both Arduino and Win8.1, but I used SDFormatter4 to reformat it, and it's ok.

I'm no expert with SD, and just seem to have a lot of trouble with it, so:

  1. I would recommend using Bill's updated SdFat library, and maybe things will work better.

  2. this is important: whatever you do,

2a. DO NOT USE ANY SD CARD WITH THE ARDUINO THAT HAS "IMPORTANT" DATA ON IT - EVER!

2b. ALLOCATE AN SD CARD TO USE WITH ARDUINO, AND DON'T USE IT FOR ANY OTHER BACKUP STORAGE!

Other people may not agree with this, but you're less likely to lose important backup data this way. If this doesn't sound like good advice, then .... never mind :-).

Thanks, fat16lib and oric_dan!!!

I updated to to SdFat off of github, installed it, and tried Quickstart. Also got a brand-new SanDisk 8GB card, and formatted with the util from sdcard.org. I tried it before the re-format (it came formatted Fat32), and that didn't seem to work. But now it does.

Much better messages, and self-config! It actually told me which pins it was expecting, so I didn't have to switch 50 an 51 back and forth (reports vary on which is which).

It reports weird filenames (as below), but at least i can see the device! Thanks!

¸b@@@@@@.®§Ç 2050-03-28 00:07:06 16785408

§Ç¶êä¸b.Æòí 2050-03-28 00:07:06 0

®§Ç¶êä¸b.@@@ 2050-03-28 00:07:06 0

¶†û®òí¸b.@@@ 2050-03-28 00:07:06 0

å¶ä¨äú¸b.@@@ 2050-03-28 00:07:10 0

-steve

Bill can help you debug the problem. I just wanted to get your attention in regards cards being destroyed, and out-of-date IDE library.

I have several 8+ GB cards with back-up data from my tablet and notebooks, and I would never ever stick one of these cards into an Arduino system. Too much to lose. So, I have a couple of small SD cards for Arduino use, which I will read on the PCs, but not store PC backup data on.

It reports weird filenames (as below), but at least i can see the device! Thanks!

How did you create the files on the card?

This version of SdFat: GitHub - greiman/SdFat: Arduino FAT16/FAT32 exFAT Library

Only supports standard 8.3 files names.

Legal characters for 8.3 file names include the following

Upper case letters A–Z

Numbers 0–9

! # $ % & ' ( ) - @ ^ _ ` { } ~

This beta version: GitHub - greiman/SdFat-beta: Beta SdFat for test of new features

Supports a limited set of long file names.

Here is a quote from the html documentation for SdFat-beta:

SdFat supports Long File Names. Long names in SdFat are limited to 7-bit ASCII characters in the range 0X20 - 0X7E The following are reserved characters:

< (less than)

(greater than)
: (colon)
" (double quote)
/ (forward slash)
\ (backslash)
| (vertical bar or pipe)
? (question mark)

  • (asterisk)

-Ghorg <--Thread hijacker. BURN! :slight_smile:

Ghorg,

Please start a new topic for your problem.