Pages: [1]   Go Down
Author Topic: Cant get SD card working  (Read 13439 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 18
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I have a Mega 2560 and an Ethernet shield.  The Ethernet part works. I put in a Micro SD card in the socket and I tried both the datalogging and the ReadWrite example. I always get the message -

Initializing SD card...initialization failed!
 
I had the card formatted FAT32 previously, so I reformatted it FAT16 and used the "default" allocation size (64K).
The card works perfectly in every computer I put it in.

So my questions are:
Do I have to format the card first in a PC?
If so, what is the correct format?
What else am I doing wrong?
Logged

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 597
Posts: 33301
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

It could be the card, some SD cards especially the lower capacity ones won't work on some of the shields around. Try another card of at least 2G.
« Last Edit: January 21, 2011, 06:41:55 am by Grumpy_Mike » Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 18
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I'll try another, but the card I was using was a 4GB  Transcend brand
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 18
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

OK, I just bought a 16GB Class 10 micro SD card.  I get the same message -

Initializing SD card...Card failed, or not present


I could probably hook up a logic analyzer,  but before I do, is there anything else?
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 18
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I read on another post that the SD memory had to be formatted FAT16 and smaller than 2GB, so I set the partition size to be 1GB and formatted it as FAT16.

STILL no luck!  Could it be that the pin declaration file is wrong for my Mega 2560?
Logged

Left Coast, USA
Offline Offline
Sr. Member
****
Karma: 5
Posts: 499
Sometimes I just can't help myself.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The datalogger example of the SD library has a bug. that makes the sketch not work with a Mega board and an Ethernet shield. It leaves the Ethernet chip selected, and this disrupts operations on the SPI port.  (The same bug appears in the other SD example sketches.)

For Mega boards, you can add a line to the setup() function to make sure that the Wiznet chip is not selected.

Open the datalogger sketch and put a digitalWrite(10, HIGH); statement right after the pinMode statement:
Code:
void setup()
{
  Serial.begin(9600);
  Serial.print("Initializing SD card...");
  // For Mega boards with an Ethernet shield, make sure the Wiznet
  // chip is not selected:
  pinMode(10, OUTPUT);
  digitalWrite(10, HIGH); // davekw7x: If it's low, the Wiznet chip corrupts the SPI bus
  
  // see if the card is present and can be initialized:
  if (!SD.begin(chipSelect)) {
    Serial.println("Card failed, or not present");
    // don't do anything more:
    return;
  }
  Serial.println("card initialized.");
}
Note that this change does not affect operation of '328 boards.  The pinMode and digitalWrite statements are both unnecessary, but do not cause any problems.


Note, finally, that you do not (that's not) have to reformat your FAT32 cards.  The Arduino SD library is a "wrapper" for the very excellent SdFat library.  The SdFat library works perfectly for me for my smallest FAT16 card (8 Megabytes) to my largest FAT32 card (8 Gigabytes).  It's true that FAT12 cards do have to be reformatted to FAT16, but that's not a very big deal (in my opinion).

Regards,

Dave

Footnote:
I do not have a Mega2560 board.  My tests were carried out with a Mega1280 and the new Ethernet Shield.  I don't know why the Arduino developers chose not to include more of the SdFat library examples.  For me, SdFatInfo has been the single most helpful debugging tool for testing different hardware designs..  The others SdFat example sketches are extremely helpful in understanding basic operations on SD cards and their files.
« Last Edit: January 22, 2011, 11:29:23 am by davekw7x » Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 18
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks, Dave!  That worked.

Logged

Pages: [1]   Go Up
Jump to: