working on a program using STM32F103C8T6 where I encounter a problem reading files from an SD card

Good evening guys , I'm working on a program using an STM32F103C8T6 microcontroller where I encounter a problem reading files from an SD card. Here's the relevant part of my program:
if (!SD.begin(CHIP_SELECT)) {
affErreur("CARTE SD");
}
initSeqFP();
dataFile = SD.open("ProgFP.txt"); // Programming file
if (dataFile) {
uint8_t i = 0;
while (dataFile.available()) {
FP[i] = dataFile.readStringUntil('\r\n');
i++;
}
dataFile.close();
litSeqFP();
}
dataFile = SD.open("MaJDate.txt"); // Date update file
if (dataFile) {
Serial.println("MaJDate.txt file opened");
uint16_t v[4];
uint8_t i = 0;
while (dataFile.available()) {
v[i] = dataFile.readStringUntil('\r\n').toInt();
i++;
}
dataFile.close();
// rtc.setDate(v[0], v[1], v[2], v[3]);
SD.remove("MaJDate.txt");
}
if (!SD.begin(CHIP_SELECT)) {
affErreur("CARTE SD");
}
initSeqFP();
dataFile = SD.open("ProgFP.txt"); // Programming file
if (dataFile) {
uint8_t i = 0;
while (dataFile.available()) {
FP[i] = dataFile.readStringUntil('\r\n');
i++;
}
dataFile.close();
litSeqFP();
}
dataFile = SD.open("MaJDate.txt"); // Date update file
if (dataFile) {
Serial.println("MaJDate.txt file opened");
uint16_t v[4];
uint8_t i = 0;
while (dataFile.available()) {
v[i] = dataFile.readStringUntil('\r\n').toInt();
i++;
}
dataFile.close();
// rtc.setDate(v[0], v[1], v[2], v[3]);
SD.remove("MaJDate.txt");
}
Solution:
Check the available memory before and after each file operation to see if you're running out of RAM.
Jump to solution
6 Replies
Camila_99$$
Camila_99$$5mo ago
When I comment out reading the second file (MaJDate.txt), reading the ProgFP.txt file works fine. However, when MaJDate.txt is uncommented, the program gets stuck while reading that file. Additional Information: -I did not receive a specific error message; the program simply hangs. -Both ProgFP.txt and MaJDate.txt are text files. -ProgFP.txt contains several lines of text, and MaJDate.txt contains numerical data separated by new lines. -I am using the Arduino SD library for file operations. -No other code sections interact with the SD card or file operations directly. What might be causing this issue with reading both files sequentially???
Enthernet Code
Enthernet Code5mo ago
@Camila_99$$ is the file path to your MajDate.txt correct, and wats it's size
Enthernet Code
Enthernet Code5mo ago
Thanks @Marvee Amasi @Camila_99$$ this was indeed really helpful I would let u guys know how it panned out
Camila_99$$
Camila_99$$5mo ago
Hii yes, the file path to MaJDate.txt is correct. The file is located in the root directory of the SD card, just like ProgFP.txt. The size of MaJDate.txt is approximately 13 bytes.
Camila_99$$
Camila_99$$5mo ago
Could the size or format of the file be causing this issue, or is there something else I should check? @Enthernet Code
Solution
wafa_ath
wafa_ath5mo ago
Check the available memory before and after each file operation to see if you're running out of RAM.
Want results from more Discord servers?
Add your server