How to edit an existing .csv file in the SD card?
I want to save constant data on .csv files in an SD card. I managed to create the file, but when I call the function to edit, it seems not to recognize the end of the file to start writing. How can I do that? Or what can I do different? That's the part where it creates and edits the file, and the f_lseek function it's supposed to find the end of the file. Also, I'm running in a 4096 size buffer and using fatfs_sd.h library.
fresult = f_open(&fil, "Test_Data_13-02.csv", FA_OPEN_ALWAYS | FA_WRITE);
fresult = f_lseek(&fil, filinfo.fsize);
fresult = f_puts("------------------- New Test -------------------\n", &fil);
for(test= 0; test < 10;test++)
{
for(test2 = 10; test2 < 20; test2++)
{
fresult = f_printf(&fil, "%d,%d,\n", test, test2);
HAL_Delay(100);
}
HAL_Delay(100);
}
fresult = f_close(&fil);
//Open to read
fresult = f_open(&fil, "Test_Data_13-02.csv", FA_READ);
//Read string from the file
f_read(&fil, buffer, filinfo.fsize, &br);
f_close(&fil);
bufclear();