Hi Runar,
You said:The if sentence is running constantly, printing the error.
Do you mean, if run it the first time, it has no error, but if you run the open code constantly, it will printing error.
Take care, after your open the file, you should close it before the next open.
so please modify your code like this:
ds = disk_initialize(SD);
if(ds)
{
printf("\nFailed to initialize SD disk\r\n");
for(;;){}
}
if(fr)
{
// printf("\nError mounting file system\r\n");
}
-------------------------------------------------------------------------------------------------------------
and;
-------------------------------------------------------------------------------------------------------------
fr = f_open(&fil, "logdata.txt", FA_WRITE | FA_OPEN_ALWAYS);
if(fr)
{
printf("\nError opening text file\r\n");
for(;;){}
}
fr = f_close(&fil);
if(fr)
{
printf("\nError closing text file\r\n");
for(;;){}
}
Please try it again!
Have a great day,
Jingjing
-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------