Answer the question
In order to leave comments, you need to log in
Arduino + SD card stops recording after turning off, powering on SD card?
General design description:
There is an ATmega328P-PU with an ARDUINO bootloader. MicroSD card adapter from CATALEX ver. 1.0 11/01/2013. The whole structure is assembled on a breadboard. Attached the diagram.
General idea: the microcontroller turns on the power of the SD card, makes a recording, turns off the power of the SD card.
Problem: The first run is fine. But after the ATmega turns off, turns on the SD power, it either freezes at the initialization stage or pretends to write, but there is no data in the file when checking.
Code option #1:
#include
#include
File myFile;
void setup(void) {
Serial.begin(115200);
pinMode(10, OUTPUT);
if (!SD.begin(10)) { digitalWrite(9, HIGH); return; }
}
void loop(void) {
digitalWrite(8, HIGH);rawd();digitalWrite(8, LOW);
delay(5000);}
void rawd () {
myFile = SD.open("sdcard.txt", FILE_WRITE);
if (myFile) {
myFile.print("&TEST1&");
Serial.print("&TEST1&");
myFile.print("&TEST2&");
Serial.print("&TEST2&");
myFile.print("&TEST3&");
Serial.print("&TEST3&");
Serial.println("");
myFile.println("");
myFile.close();}
else {digitalWrite(9, HIGH);}}
We do not control the process of interaction with the SD card in any way, we only turn the power of the MicroSD card adapter on and off. Starts to slowly write to the SD card, but does not actually write anything.
Code option #2:
#include
#include
File myFile;
void setup(void) {
Serial.begin(115200);
pinMode(10, OUTPUT);
if (!SD.begin(10)) { digitalWrite(9, HIGH); return; }
}
void loop(void) {
digitalWrite(8, HIGH);rawd();digitalWrite(8, LOW);
delay(5000);}
void rawd() {
digitalWrite(10, LOW);
myFile = SD.open("sdcard.txt", FILE_WRITE);
if (myFile) {
myFile.print("&TEST1&");
Serial.print("&TEST1&");
myFile.print("&TEST2&");
Serial.print("&TEST2&");
myFile.print("&TEST3&");
Serial.print("&TEST3&");
Serial.println("");
myFile.println("");
myFile.close();
digitalWrite(10, HIGH);
}
else {digitalWrite(9, HIGH);}}
Trying to unplug the SD card after the write is complete. Or even hangs or does not write to the SD card.
Code option #3:
#include
#include
File myFile;
void setup(void) {
Serial.begin(115200);
pinMode(10, OUTPUT);
}
void loop(void) {
digitalWrite(8, HIGH);rawd();digitalWrite(8, LOW);
delay(5000);}
void rawd () {
while(!SD.begin(10)) {digitalWrite(9, HIGH);delay(100);Serial.print(".");}
myFile = SD.open( "sdcard.txt", FILE_WRITE);
if (myFile) {
myFile.print("&TEST1&");
Serial.print("&TEST1&");
myFile.print("&TEST2&");
Serial.print("&TEST2&");
myFile.print("&TEST3&");
Serial.print("&TEST3&");
Serial.println("");
myFile.println("");
myFile.close();
digitalWrite(10, HIGH);
}
else {digitalWrite(9, HIGH);}} We
initialize SD every time we are going to write. But for the second time we hang in a loop due to the fact that SD cannot be initialized. The strangest thing is that the first time everything goes fine, the problem occurs when the action is repeated.
Most likely, I am not correctly disabling the SD card, but I could not find examples of how to do this correctly.
Answer the question
In order to leave comments, you need to log in
When writing to a file, the actual writing occurs only after the file.flush() or file.close() command. You send the command "write data" and immediately turn off the power. Therefore, the recording does not have time to occur.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question