UPDATED: HTCC-ABO2S not writing data to csv with SD Card Reader

I am struggling to get my microSD card reader to work with my HTCC-ABO2S (GPS-6052) board.
The microSD card reader I am using works perfectly with an ESP32 and mostly identical code. I am able to read and write files off the SD card using the CubeCell board, but it will not write data to a file.

My pin setup is currently:
MISO – 26 (MISO0)
MOSI – 25 (MOSI0)
SCK – 27 (CLK0)
CS – 41 (GPIO11)

I have also tried using the other MISO, MOSI, and CLK pins with no success. I would actually prefer to use these, as I need the others for LoRa, but I’ll cross that bridge when I get to it.

All assistance and/or suggestions are much appreciated.

UPDATE:
Below are 2 very unusual things that I have noticed while trying to get this to work…

  1. dataFile = SD.open(filePath, FILE_APPEND); does not compile unless I switch FILE_APPEND to FILE_WRITE. This shouldn’t realistically be a huge problem, but is very unusual.
  2. If I run dataFile = SD.open(filePath, FILE_WRITE); followed by if(dataFile){}, the if statement will always return false. This is quite odd, and I’m not exactly sure what it indicates. If I instead run if (!SD.exists(filePath)), it will return true as expected.

Updated code:

//#include "FS.h"   // Will not compile with FS.h, this may or may not be causing problems
#include "SPI.h"
#include "SD.h"

bool fileLooping = false;
String filePath = "/TEST_0.csv";
int fileConstant = 0;
File dataFile;
const int chipSelect = 41;

/* WAIT FUNCTION */
inline void wait(unsigned long const& t) {
unsigned long sTime = millis();
while (millis() - sTime <= t);
}

void setup() {
  Serial.begin(115200);    // Open serial
  while (!Serial) {}       // Wait for serial

  pinMode(chipSelect,OUTPUT);
  digitalWrite(chipSelect,LOW);
  
  Serial.print("Initializing SD card...");

  if (!SD.begin(chipSelect)) {      // This works, SD initializes just fine
    Serial.println("Card failed, or not present");
    while(1){}
  }
  Serial.println("card initialized.");
  while(fileLooping == true){
    if (!SD.exists(filePath)) {                  // CHECK IF CSV FILE ALREADY EXISTS OR NOT (This works)
      dataFile = SD.open(filePath, FILE_WRITE);  // WRITE CSV FILE TO SD CARD
      wait(1000);
      if (!dataFile) {          // Always returns "failed to write," even though it actually does write the file
        Serial.println("FAILED TO WRITE " + filePath + " TO SD CARD. CONTINUING REGARDLESS.");
        dataFile.close();  //CLOSE FILE
        return;
      } else {
        Serial.println(filePath + " SUCCESSFULLY WRITTEN TO SD CARD.");
        dataFile.close();  //CLOSE FILE
        fileLooping = false;
        break;
      }
    } else {
      Serial.println(filePath + " ALREADY EXISTS ON SD CARD. TRYING AGAIN WITH DIFFERENT FILE NAME.");
      fileConstant++;       
      filePath = "/TEST_" + String(fileConstant) + ".csv";         // Try again with different file name until file name is unique on SD card (This works)
    }
  }
}

void loop() {
  wait(1000);
  String dataString = "Test,1,2";
  wait(1000);
  if (!SD.exists(filePath)) {
    Serial.println("!!!!! UNABLE TO OPEN " + filePath + " TO PRINT DATA !!!!!");
  } else {
    dataFile = SD.open(filePath, FILE_WRITE);  // OPEN THE FILE
    if (dataFile) {
      dataFile.println(dataString);             // WRITE DATA
      dataFile.close();                         // CLOSE THE FILE
      Serial.println("CSV HEADERS SUCCESSFULLY WRITTEN TO " + filePath);
    } else {
      Serial.println("!!!!! ERROR PRINTING DATA TO " + filePath + " !!!!!");  // Always prints this & does not write data to file
    }
  }
}

Hello, could you find a solution to save the data on the microSD?
I have the same problem as you and I can’t find any solution, I have tried several ways and none of them work, could you please help me?


This is the schematic diagram of AB02s, hoping it will be helpful to you.