SD card inited but failed to read or write...
Posted: Sat Oct 03, 2020 5:44 pm
Hi guys! Please help if any chanse... I have stuck with the strange problem...
I am prototyping an simple board based on TTGO esp32 board... OLED had started instantly. But SD card inited, correct detected, returns right size and free space... but there is no chans to open for reading or writing file with the simplest name "1"... or any other name...
SD adapter - the most simple one (4 resistors to the 3.3V and two capasitors), Voltage 3.31V.
Actually the source code of my test:
[Codebox]
#include <SPI.h>
#include <SD.h>
#define SD_SC_PIN 5
void setup() {
Serial.begin(115200);
Serial.print("Initializing SD card...");
if (!SD.begin(SD_SC_PIN)) {
Serial.println("Card failed, or not present");
while (1);
}
Serial.println("card initialized.");
SPI.setClockDivider(SPI_CLOCK_DIV128);
uint8_t cardType = SD.cardType();
if(cardType == CARD_NONE){
Serial.println("No card attached");
return;
}
Serial.print("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");
}
Serial.print("Card size (Mb): ");
Serial.println((int)(SD.cardSize()/1048576));
Serial.print(" Available (Mb):");
Serial.println((int)(SD.totalBytes()/1048576));
Serial.print(" Used (Mb):");
Serial.println((int)(SD.usedBytes()/1048576));
}
const char *fileName = "1";
void loop() {
//File dataFile = SD.open(fileName,FILE_WRITE);
File dataFile = SD.open(fileName,FILE_READ);
if(dataFile){
Serial.print("Opened file:"); Serial.println(fileName);
dataFile.close();
} else {
//Serial.print("Can't create file: "); Serial.println(fileName);
}
}
[/Codebox]
The output:
Thank you in advance!!!
I am prototyping an simple board based on TTGO esp32 board... OLED had started instantly. But SD card inited, correct detected, returns right size and free space... but there is no chans to open for reading or writing file with the simplest name "1"... or any other name...
SD adapter - the most simple one (4 resistors to the 3.3V and two capasitors), Voltage 3.31V.
Actually the source code of my test:
[Codebox]
#include <SPI.h>
#include <SD.h>
#define SD_SC_PIN 5
void setup() {
Serial.begin(115200);
Serial.print("Initializing SD card...");
if (!SD.begin(SD_SC_PIN)) {
Serial.println("Card failed, or not present");
while (1);
}
Serial.println("card initialized.");
SPI.setClockDivider(SPI_CLOCK_DIV128);
uint8_t cardType = SD.cardType();
if(cardType == CARD_NONE){
Serial.println("No card attached");
return;
}
Serial.print("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");
}
Serial.print("Card size (Mb): ");
Serial.println((int)(SD.cardSize()/1048576));
Serial.print(" Available (Mb):");
Serial.println((int)(SD.totalBytes()/1048576));
Serial.print(" Used (Mb):");
Serial.println((int)(SD.usedBytes()/1048576));
}
const char *fileName = "1";
void loop() {
//File dataFile = SD.open(fileName,FILE_WRITE);
File dataFile = SD.open(fileName,FILE_READ);
if(dataFile){
Serial.print("Opened file:"); Serial.println(fileName);
dataFile.close();
} else {
//Serial.print("Can't create file: "); Serial.println(fileName);
}
}
[/Codebox]
The output:
Hope I am doing something really simple and stupid!ets Jun 8 2016 00:22:57
rst:0x1 (POWERON_RESET),boot:0x17 (SPI_FAST_FLASH_BOOT)
configsip: 188777542, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:2
load:0x3fff0018,len:4
load:0x3fff001c,len:1044
load:0x40078000,len:8896
load:0x40080400,len:5828
entry 0x400806ac
Initializing SD card...card initialized.
Card type: SDHC
Card size (Mb): 30480
Available (Mb):30460
Used (Mb):40
Thank you in advance!!!