SD-card: initialization failed!

Hi,

I have problems with an SD-card-reader. I always get this message: "Initializing SD card...initialization failed!"

The software is taken from file -> examples -> SD -> listfiles

Environment: Arduino Ide 1.8.5 with SDFat 1.0.7
Board: Arduino Uno (in future: seeeduino)
Wiring:
MOSI - pin 11
MISO - pin 12
CLK - pin 13
CS - pin 4 (same behavior for 10)
3.3V (same for 5V)
GND

I got this message for the seeeduino-board so I switched to the Arduino Uno: same.

The problem is the first line of code accessing the SD-card-reader:

serialConnection.print("Initializing SD card...");

if (!SD.begin(4)) {
serialConnection.println("initialization failed!");
while (1);
}

Can you please give me a tip.
Thanks
AugustQ

forgotten:
card is 32GB, formatted with FAT32
For a test I created a partitioon of size 4GB and formatted this with FAT16 -> same result.

AugustQ:
forgotten:
card is 32GB, formatted with FAT32
For a test I created a partitioon of size 4GB and formatted this with FAT16 -> same result.

You formatted the card using what?

show the whole sketch. you use SdFat library?

Also try CardInfo and tell us the result.

Thanks for the answers.

I had the problem with the card fresh from the dealer. Later I re-formatted it within Ubuntu (18.04). Later I created a 4GB partition on it and formatted it via a console:
$ sudo mkdosfs -F 16 /dev/sdc1

This is my sketch:

/*
Listfiles

This example shows how print out the files in a
directory on a SD card

The circuit:

  • SD card attached to SPI bus as follows:
    ** MOSI - pin 11
    ** MISO - pin 12
    ** CLK - pin 13
    ** CS - pin 4 (for MKRZero SD: SDCARD_SS_PIN)

created Nov 2010
by David A. Mellis
modified 9 Apr 2012
by Tom Igoe
modified 2 Feb 2014
by Scott Fitzgerald

This example code is in the public domain.

*/
#include <SPI.h>
#include <SD.h>

#define serialConnection Serial

File root;

void setup() {
// Open serial communications and wait for port to open:
serialConnection.begin(57600);
while (!serialConnection.available()) {
; // wait for serial port to connect. Needed for native USB port only
}

serialConnection.print("Initializing SD card...");
pinMode(4, OUTPUT); // SD Card CS
if (!SD.begin(4)) {
serialConnection.println("initialization failed!");
while (1);
}
serialConnection.println("initialization done.");

root = SD.open("/");

printDirectory(root, 0);

serialConnection.println("done!");
}

void loop() {
// nothing happens after setup finishes.
}

void printDirectory(File dir, int numTabs) {
while (true) {

File entry = dir.openNextFile();
if (! entry) {
// no more files
break;
}
for (uint8_t i = 0; i < numTabs; i++) {
serialConnection.print('\t');
}
serialConnection.print(entry.name());
if (entry.isDirectory()) {
serialConnection.println("/");
printDirectory(entry, numTabs + 1);
} else {
// files have sizes, directories do not
serialConnection.print("\t\t");
serialConnection.println(entry.size(), DEC);
}
entry.close();
}
}

And cardinfo shows this:

Initializing SD card...initialization failed. Things to check:

  • is a card inserted?
  • is your wiring correct?
  • did you change the chipSelect pin to match your shield or module?

Oh, that's new: is a card inserted?

I will try to find another SD-card.

I tried another card: some problem.

OK, so please stop.

I changed the adapter and the card, checked the wiring. An now I got this:

Initializing SD card...Wiring is correct and a card is present.

Card type: SDHC
Could not find FAT16/FAT32 partition.
Make sure you've formatted the card

Good, a different message. I will look at this tomorrow. Enough for today.

AugustQ

PS: at least my wiring seems to be OK.

AugustQ:
OK, so please stop.

I changed the adapter and the card, checked the wiring. An now I got this:
Good, a different message. I will look at this tomorrow. Enough for today.

AugustQ

PS: at least my wiring seems to be OK.

first of all, you used a different sketch

AugustQ:
I changed the adapter and the card, checked the wiring. An now I got this:

Initializing SD card...Wiring is correct and a card is present.

Card type:        SDHC
Could not find FAT16/FAT32 partition.
Make sure you've formatted the card

Something is messed up with the partition table since:

AugustQ:
card is 32GB, formatted with FAT32
For a test I created a partitioon of size 4GB and formatted this with FAT16

Better use SDFormatter or the formatter example sketch on SdFat.

Hi,

it still works. So the problem is solved.

The main problem is that it only works with 5V, not with 3.3V (as described).

The second problem was that the SD-card used in my first tests had some problems (I will look into this later).

So here is what I did step by step:

  • I changed the SD-card
  • I changed the card-reader
  • I switched to 5V.

Then it works (as described yesterday).

Today I checked it again: still works. Then I formatted the SD-card again using the full 16GB of the card: still works. Then I switched to 3.3V: init failed. Switching back to 5V: everything works.

I tested it with 3 sketches from the example and they all work.

Thanks for your patience and your tips.
AugustQ

AugustQ:

  • I changed the card-reader
  • I switched to 5V.

Today I checked it again: still works. Then I formatted the SD-card again using the full 16GB of the card: still works. Then I switched to 3.3V: init failed. Switching back to 5V: everything works.

The best to would be to provide a link to the card readers (yes, plural) that you used. One or both of them must have a built in level shifter and is expecting 5V. Yes the cards are 3.3V only, but if it requires 5V to work, then there must be a level shifter or the SD card IS going to smoke.

Hi,

this is the card-reader I used:
https://www.aliexpress.com/item/Micro-SD-card-mini-TF-card-reader-module-SPI-interfaces-with-level-converter-chip-for-arduino/32424558182.html?spm=a2g0s.9042311.0.0.3a974c4d9DfM6W

I ordered 5 of them so I used another one of the same type.

As I'm coming from software I am helpless in this part of the job.

AugustQ

AugustQ:
Hi,

this is the card-reader I used:
https://www.aliexpress.com/item/Micro-SD-card-mini-TF-card-reader-module-SPI-interfaces-with-level-converter-chip-for-arduino/32424558182.html?spm=a2g0s.9042311.0.0.3a974c4d9DfM6W

I ordered 5 of them so I used another one of the same type.

As I'm coming from software I am helpless in this part of the job.

AugustQ

The Module Supply and Control Interface sections tell you everything you need to know and explains why it requires 5V.

AugustQ:
this is the card-reader I used:
https://www.aliexpress.com/item/Micro-SD-card-mini-TF-card-reader-module-SPI-interfaces-with-level-converter-chip-for-arduino/32424558182.html?spm=a2g0s.9042311.0.0.3a974c4d9DfM6W

Makes sense. The module only has one "Vcc" (power input) pin, and it's wired to a 3.3v regulator.
Powering a 3.3v regulator with that voltage, results in a even lower output; so low that renders the SD card inoperable (but not destroyed fortunately).

And yes, it has a logic level shifter for that previous reason.

Hi,

thanks for the explanations.

Now I found it on the page: in "Item specifics" I see: Supply "Voltage: 5V" .

OK. As I'm a software-guy I didn't check this.

AugustQ