cancel
Showing results for 
Search instead for 
Did you mean: 

fatfs f_read() and f_gets() return incorrect data

3nt3
Associate

When reading from an SD card using SPI and FAT32 using either f_read() or f_gets() the data returned does not match the actual file contents.

I am using an STM32F103C8.

fresult = f_open(&fil, "0:test.txt", FA_OPEN_EXISTING | FA_READ | FA_WRITE);
 
unsigned int bytesWritten = 0;
bufclear(buffer, 1024);
sprintf(buffer, "test TEST test 123");
 
fresult = f_write(&fil, buffer, bufsize(buffer), &bytesWritten);
 
char fileBuf[10];
bufclear(fileBuf, 10);
 
f_gets(fileBuf, 10, &fil);

0693W000006I5D0QAK.png

1 ACCEPTED SOLUTION

Accepted Solutions
3nt3
Associate

It was actually the "correct" output, just the file was corrupted.

View solution in original post

1 REPLY 1
3nt3
Associate

It was actually the "correct" output, just the file was corrupted.