0

i use the example sketch of SD card presented in Arduino IDE. It runs well, but when i reboot my Adruino Mega by the reset button, the SD card initialization fails. To fix it, i need to remove the SD card, insert it in his socket and reboot the board again. Then, SD card initialization is OK. How can i update my code to try initialize the SD card until initialization is OK? Also, can you explain me where come this bug ?

See the example SD card setup on the Arduino Mega:

Serial.print("Initializing SD card...");
 if (!SD.begin(53)) {
 Serial.println("initialization failed!");
 while (1);
 }
 Serial.println("initialization done.");
asked Dec 6, 2018 at 13:57
8
  • It is probably not a bug, not all sd cards are compatible with the sd library. Are you resetting the arduino while the sd card is busy? Perhaps the socket on its module is not suitable for 5v. Perhaps you use a breadboard. Perhaps the wires are too long Perhaps the arduino mega has not enough voltage due to a cheap usb cable. There are many more things that can be wrong. Commented Dec 6, 2018 at 14:04
  • is some other SPI device attached? Commented Dec 6, 2018 at 14:05
  • No other SPI device attached. I use usb cable and 20cm wires to link sd card to the arduino. I will try the work with an external 9V power supply and maybe see you soon... Commented Dec 6, 2018 at 14:21
  • After using an external power supply, initialization works well after 10 reboots !!! You're write Jot, using only the usb cable, voltage on the CS pin of SD card device is about 4.5V. With an external voltage high 5V for the arduino, CS pin of SD card device is 4.99V. I think that the problem came from here. Thanks ! Commented Dec 6, 2018 at 14:31
  • A sd card is 3.3v (or at least compatible with 3.3v). Can you show a photo of the module with the socket? Is there a chip on the module to convert the 3.3v signals from the sd card to the 5v signals of the arduino? Commented Dec 6, 2018 at 15:13

1 Answer 1

0

I just add an external 9V power supply to my Arduino Mega. The SD device is power by arduino 5V pinout.

answered Dec 6, 2018 at 23:43

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.