-
-
Notifications
You must be signed in to change notification settings - Fork 7k
Description
Hello,
I am working with the Mega ADK R3 and I have the Arduino Ethernet Shield R3 connected with an SD card.
I have made the SD card work writing files, deleting, creating directories. But unexpectedly stop working sometimes the full day.
I have not identified how it just simple start working again. I reset everything, reformat the SD, etc. But no sure what is the issue.
May be could stop working when i just simple try to read the SD card directly in the computer (Windows 7) for checking the files (but not sure).
The error is: Initializing SD card...SD Initialization failed!
I have change PIN 10 to HIGH, PIN 53 to HIGH and used the SD.begin(4).
Only tested PIN 10 and it worked a while, tested with both at the same time 10 and 53 and worked a while.
i applied the patch below in the "begin" method as well in SD.cpp but the same problem
if (root.isOpen())
{
Serial.println("Root is Open");
if (!root.close())
return false;
}
I am using arduino software 1.0.5 version
I am just putting a piece of code of the complete program, just the same example adding the digitalWrite(10,HIGH) or 53. To deactivate the Ethernet Card.
I am not using the Ethernet card yet, only the SD
Although in the code you see 10 and 53 at the same i have tried all combination, only one, both, only the last one. Thanks
Here is the code
include <SD.h>
File myFile;
void setup()
{
// Open serial communications and wait for port to open:
Serial.begin(115200);
while (!Serial) {
; // wait for serial port to connect. Needed for Leonardo only
}
Serial.print("Initializing SD card...");
// On the Ethernet Shield, CS is pin 4. It's set as an output by default. Note that even if it's not used as the CS pin, the hardware SS pin (10 on most Arduino boards, 53 on the Mega) must be left as an output or the SD library functions will not work.
pinMode(53, OUTPUT);
digitalWrite(53,HIGH); // tried both or only 10 or only 53 in HIGH but both with OUTPUT
pinMode(10, OUTPUT);
digitalWrite(10,HIGH);
if (!SD.begin(4)) {
Serial.println("SD Initialization failed!");
return;
}
Serial.println("SD Initialization done.");
if(!(SD.exists("/AWE"))) //always from the root
SD.mkdir("/AWE");
myFile = SD.open("/AWE/test.txt", FILE_WRITE);
if (myFile) {
Serial.print("Writing to test.txt...");
myFile.println("testing 1, 2, 3.");
// close the file:
myFile.close();
Serial.println("done.");
} else {
// if the file didn't open, print an error:
Serial.println("error opening test.txt");
}
// re-open the file for reading:
myFile = SD.open("/AWE/test.txt");
if (myFile) {
Serial.println("/AWE/test.txt:");
// read from the file until there's nothing else in it:
while (myFile.available()) {
Serial.write(myFile.read());
}
// close the file:
myFile.close();
} else {
// if the file didn't open, print an error:
Serial.println("error opening test.txt");
}
}
void loop()
{
// nothing happens after setup
}