i work on a group project with an ESP32. We have a lcd display and a sd card connected via the two SPI ports of the ESP32.
The card gets initialized with no problem using this code:
bool EKG_recording::initialisation_sd() {
SPIClass * hspi = new SPIClass(HSPI);
if (!SD.begin(CS_Pin, *hspi))
{
Serial.println("No valid SD card!");
return 0;
}
else if (SD.begin(CS_Pin, *hspi))
{
Serial.println("SD card initialized!");
return 1;
}
else return 0;
}
One function i have a problem with is used to count every file on the SD card, simple enough right?
unsigned short EKG_recording::count_files_from_SD(File dir) {
while (true)
{
File entry = dir.openNextFile();
if (!entry)
{
// Serial.println("Anzahl der Daten");
return counter;
}
counter++;
entry.close();
}
}
It once worked without a problem, then we integrated the two SPI ports and now i cant figure out why its not working.
This part:
File entry = dir.openNextFile();
returns false on the first call even though i am 100% sure there are 3 files on the SD card.
I call the function like this :
File root = SD.open("/"); EKG_recording_1.count_files_from_SD(root);
But why? Any help is very appreciated.