SD card inited but failed to read or write...

sergyegorov
Posts: 4
Joined: Sat Oct 03, 2020 4:57 pm

SD card inited but failed to read or write...

Postby sergyegorov » 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:
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
Hope I am doing something really simple and stupid!
Thank you in advance!!!

sergyegorov
Posts: 4
Joined: Sat Oct 03, 2020 4:57 pm

Re: SD card inited but failed to read or write...

Postby sergyegorov » Mon Oct 05, 2020 8:26 am

I have to figure out this issue!
I have changed sd card adapter from this one with no regulator and buffers:
Image
to that one with reculater and buffer:
Image
Additionaly I tried to shortcut AMS1117, due to low voltage after regulator (2.6V)...
No effect... It seems the problem is in the software but no in the hardware...

sergyegorov
Posts: 4
Joined: Sat Oct 03, 2020 4:57 pm

Re: SD card inited but failed to read or write...

Postby sergyegorov » Mon Oct 05, 2020 9:25 am

Yep!
The problem was in the library... It seems that I used original Arduino SD library instead of library from ESP32 platform.
After downloading platform source code and using exactly this library - all works even with the simplest adapterr!
Done!

sergyegorov
Posts: 4
Joined: Sat Oct 03, 2020 4:57 pm

Re: SD card inited but failed to read or write...

Postby sergyegorov » Tue Oct 06, 2020 1:31 pm

Problem was in the library... Instead the file name "1" just put "/1"... That's all! It is really stupid!

chegewara
Posts: 2364
Joined: Wed Jun 14, 2017 9:00 pm

Re: SD card inited but failed to read or write...

Postby chegewara » Sat Oct 10, 2020 8:08 pm

If you are using second adapter, with regulator, you have to connect VCC to 5V on that adapter.

Who is online

Users browsing this forum: Bing [Bot] and 66 guests