ESP32 SD writes but doesn't append

skendhajd
Posts: 1
Joined: Sat Feb 13, 2021 12:10 pm

ESP32 SD writes but doesn't append

Postby skendhajd » Sat Feb 13, 2021 12:16 pm

I've got a microSD module adapter from the far east, and so far so good, and although it can create files using writeFile, it does not append messages. It returns true, i.e: message appended successfully but when you read the file on the computer or when ESP32 reads on reboot, it's blank.

This is how I call the function:
  1. char* sdFileName = "/v.ea";
  2. if (appendFile(SD, sdFileName, "Heyy")) {
  3. //success
  4. } else {
  5. //failed
  6. }
I've even tried the writeFile function with

Code: Select all

file.seek(EOF)
but no luck. When calling appendFile for the first time, this appears:
  1. [W][sd_diskio.cpp:149] sdCommand(): token error [17] 0x17
  2. Appending succesfully.
When the appendFile is called for the second time, this appears in serial monitor:
  1. [W][sd_diskio.cpp:149] sdCommand(): token error [17] 0x17
  2. [W][sd_diskio.cpp:149] sdCommand(): token error [17] 0x5
  3. [W][sd_diskio.cpp:149] sdCommand(): token error [17] 0x5
  4. [E][vfs_api.cpp:265] VFSFileImpl(): fopen(/sd/v.ea) failed
  5. Appending failed.
I am using two SPI devices: MFRC522, and before calling SD's functions, I do a

Code: Select all

digitalWrite(SD_SS, LOW)
to "enable" the SD functions till it completes its operations and returns back to

Code: Select all

HIGH 
to disable it.

I've also tried both FAT32 and FAT, no success.
The example in SD(esp32) works fine - writing, appending, deleting, renaming, etc. all work well.

Thanks in advance.

UPDATE: seems like

Code: Select all

rfid.init();
is causing the problem. When I remove it, the appending works fine. As I said, I'm using two SPI with a 330Ohm resistor between MISO and microSD adapter module. Though, before SD functions, I use this function:
  1. void activate_SD() {
  2.   rfid.PCD_SoftPowerDown();
  3.   digitalWrite(MFRC522_SSPin, HIGH);
  4.   digitalWrite(SDMOD_SS, LOW);
  5.   if (DEBUG == 1) {
  6.     Serial.println("SD is active.");
  7.   }
  8. }
Then after SD operations are completed, I use this:
  1. void activate_RFID() {
  2.   rfid.PCD_SoftPowerUp();
  3.   rfid.PCD_Init();
  4.   digitalWrite(SDMOD_SS, HIGH);
  5.   digitalWrite(MFRC522_SSPin, LOW);
  6.   if (DEBUG == 1) {
  7.     Serial.println("RFID is active.");
  8.   }
  9. }
But it doesn't help.

Who is online

Users browsing this forum: Majestic-12 [Bot] and 58 guests