I have implemented the FatFs file system onto a 28335 with partial sucess. I can read a file ok but cannot write sucessfully. I'm using a 2GB SD formatted to FAT32 in Windows 7. When writing to a file, I can open the filename with sucess, but on writing it appears to overwrite any existing file. I then attempt to read back the data but this fails. Reading it back on the PC there are no files. If I do a 'check now' under properties, the file can be recovered as FILE0000.CHK. I feel I'm close to solving the problem but I've spent too much time and need help please?
I maybe writing to a wrong sector or overwriting to an existing location. Can anyone help please? I've followed a previous thread but alas this was not fully concluded and is now dead. Thanks Geoff
fresult = f_mount(0, &fs[0]);
uart_printf("Create file fileXYZ.txt\n\r");
fresult = f_open(&fsrc,"/fileXYZ.txt", FA_CREATE_ALWAYS | FA_WRITE );
uart_printf("f_open code: %s\n",StringFromFresult(fresult < RETURNS FR_OK>
uart_printf("Write a message (Hello World!)\n\r");
fresult = f_write(&fsrc,"Hello World!\0",14, &bw);
uart_printf("f_write code: %s\n", StringFromFresult(fresult)); RETURNS <FR_OK>
uart_printf("%d bytes written.\n",bw); prints <14 bytes written>
f_close(&fsrc); /* Close open files */
uart_printf("f_close: %s\r\n", StringFromFresult(fresult)); RETURNS <FR_OK
fresult = f_open(&fsrc,"/fileXYZ.txt", FA_OPEN_EXISTING | FA_READ);
uart_printf(f_open code: %s\r\n", StringFromFresult(fresult)); RETURNS <FR_OK>
uart_printf("fileXYZ.txt contents\r\n");
for(;;)
{
fresult = f_read(&fsrc,Buff,sizeof Buff,&br); /* read file */
if (fresult || !br) break;
uart_printf(Buff); NOTHING PRINTED HERE
}
uart_printf(Buff);
fresult = f_close(&fsrc);
uart_printf("f_close: %s\r\n", StringFromFresult(fresult)); RETURNS <FR_OK>
/* Unregister work area prior to discard it */
f_mount(0,NULL);