ESP32-S3 SD NAND openNextFile returning on results
Posted: Tue Oct 31, 2023 7:29 am
I'm running the SD example code on an ESP32-S3 dev module and I am getting no return content when using openNextFile(). I am building with Arduino IDE 2.2.1 and ESP32 v 2.0.14. When I call openNextFile() I get no results.
Here is the code:
ideas why?
-Frank
Here is the code:
Code: Select all
#include <Arduino.h>
#include "FS.h"
#include <LittleFS.h>
#include "SPI.h"
#define SPI_SCK 36
#define SPI_MISO 37
#define SPI_MOSI 35
#define SD_CS 15
// Display
#define Display_SPI_DC 5
#define Display_SPI_CS 12
#define Display_SPI_RST 0
#define Display_SPI_BK 6
boolean listDir(fs::FS &fs, const char * dirname, uint8_t levels, bool monitor){
Serial.printf("Listing directory: %s\n", dirname);
File root = fs.open(dirname);
if(!root){
Serial.print( F( "Failed to open directory w: " ) );
Serial.println( dirname );
return false;
}
if(!root.isDirectory()){
Serial.println( F( "Not a directory" ) );
return false;
}
Serial.print( "root = " );
Serial.println( root.path() );
File file = root.openNextFile();
Serial.print( "file = " );
Serial.println( file );
Serial.print( "file.path = " );
Serial.println( file.path() );
while ( file )
{
if ( file.isDirectory() )
{
if ( monitor )
{
Serial.print( F( " DIR : " ) );
Serial.println(file.name());
}
if(levels)
{
String fname2 = file.name();
String fname3 = "/" + fname2;
listDir(fs, fname3.c_str(), levels -1, monitor);
}
}
else
{
if ( monitor )
{
Serial.print(" FILE: ");
Serial.print(file.name());
Serial.print(" SIZE: ");
Serial.println(file.size());
}
}
file = root.openNextFile();
}
root.close();
return true;
}
void setup(){
Serial.begin(115200);
delay(1000);
Serial.println("Starting");
SPI.begin(SPI_SCK, SPI_MISO, SPI_MOSI, -1);
delay(1000);
pinMode(SD_CS, OUTPUT ); // Turn power on to NAND
digitalWrite(SD_CS, LOW);
pinMode(Display_SPI_CS, OUTPUT);
digitalWrite(Display_SPI_CS, LOW);
pinMode(Display_SPI_DC, OUTPUT);
digitalWrite(Display_SPI_DC, HIGH);
pinMode(Display_SPI_RST, OUTPUT);
digitalWrite(Display_SPI_RST, HIGH);
pinMode(Display_SPI_BK, OUTPUT);
digitalWrite(Display_SPI_BK, LOW);
delay(1000);
if ( !SD.begin( SD_CS ) )
{
Serial.println("Card Mount Failed");
return;
}
uint8_t cardType = SD.cardType();
if(cardType == CARD_NONE){
Serial.println("No SD card attached");
return;
}
Serial.print("SD Card Type: ");
if(cardType == CARD_MMC){
Serial.println("MMC");
} else if(cardType == CARD_SD){
Serial.println("SDSC");
} else if(cardType == CARD_SDHC){
Serial.println("SDHC");
} else {
Serial.println("UNKNOWN");
}
uint64_t cardSize = SD.cardSize() / (1024 * 1024);
Serial.printf("SD Card Size: %lluMB\n", cardSize);
listDir(SD, "/", 100, true);
Serial.println("-end-");
}
void loop()
{
}
-Frank