Petit FatFs Write Problem

1 post / 0 new
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0



I'm currently trying to use Petit FatFs to edit a file held on an SD card with values retrieved from a sensor connected to my ATxmega128A3U. The readings are periodically written to the same file.


I've mounted the volume successfully and opened the required file. The first write is done without any problems, but any subsequent accesses return an FR_NOT_OPENED result.


The only solution I've found to this problem is remounting the volume and re-opening the file before each write. But this is taking too much time, especially when using the pf_lseek() function to access sectors with a larger index.


Is this the normal mode of operation, or should successive writes be successful without the need for remounting the volume and/or re-opening the file? 


For reference, below is the code I'm using:


while((status = pf_mount(&fileSystem)) != FR_OK)
sector *= 512;
unsigned long sectorL = (long)sector;
status = pf_lseek(sectorL);
pf_write(buff, bytes_to_write, &bytes_written);
pf_write(0, 0, 0);

where sector is an argument passed to the function and incremented on every call.

Last Edited: Thu. Oct 12, 2017 - 07:14 AM