ESP32 SD writes but doesn't append

I've got a microSD module adapter 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:

char* sdFileName = "/v.ea";
if (appendFile(SD, sdFileName, "TEST")) {
//success
} else {
//failed
}

I've even tried the writeFile function with file.seek(EOF) but no luck. When calling appendFile for the first time, this appears:

[W][sd_diskio.cpp:149] sdCommand(): token error [17] 0x17
Appending succesfully.

When the appendFile is called for the second time, this appears in serial monitor:

[W][sd_diskio.cpp:149] sdCommand(): token error [17] 0x17
[W][sd_diskio.cpp:149] sdCommand(): token error [17] 0x5
[W][sd_diskio.cpp:149] sdCommand(): token error [17] 0x5
[E][vfs_api.cpp:265] VFSFileImpl(): fopen(/sd/v.ea) failed
Appending failed.

I am using two SPI devices: MFRC522, and before calling SD's functions, I do a digitalWrite(SD_SS, LOW) to "enable" the SD functions till it completes its operations and returns back to 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.

The culprit as I've found is: 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:

void activate_SD() {
  digitalWrite(MFRC522_SSPin, HIGH);
  digitalWrite(SDMOD_SS, LOW);
  if (DEBUG == 1) {
    Serial.println("SD is active.");
  }
}

Then after SD operations are completed, I use this:

void activate_RFID() {
  digitalWrite(SDMOD_SS, HIGH);
  digitalWrite(MFRC522_SSPin, LOW);
  if (DEBUG == 1) {
    Serial.println("RFID is active.");
  }
}

But it doesn't help. I've been stuck on this problem for a couple of weeks. I even tried a 2.2KOhm resistor but same result. Don't really know what to try else. Thanks in advance.

And no reply on the other forums either, surprised Expressif did not respond, its their software.

https://www.esp32.com/viewtopic.php?t=19457&p=71885

srnet:
And no reply on the other forums either, surprised Expressif did not respond, its their software.

sd card - ESP32 SD writes but doesn't append - Arduino Stack Exchange

ESP32 SD writes but doesn't append - ESP32 Forum

To be honest, I don't know where else to post. Tried lots of solutions, from different sources, including some from here but no luck. I don't really know what I'm doing wrong.

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.