首先我改写了实验例程,在main函数中,while(1)之前加入了如下代码: #define FILE_WRITE_BUFF_LEN 128 #define FILE_READ_BUFF_LEN 1024
u8 g_file_read_buff[FILE_READ_BUFF_LEN] = {0};
FIL f_record;
FRESULT f_res = FR_DISK_ERR;
UINT file_write_position_point = 0;
UINT file_read_position_point = 0;
………………………………………………
………………………………………………
memset(&f_record,0,sizeof(FIL));
f_res = f_open(&f_record,"0:/Rrcord.txt",FA_OPEN_ALWAYS | FA_READ | FA_WRITE);
if (FR_OK != f_res)
{
printf("%s %d Record.txt open failed!
",__FILE__,__LINE__);
memset(&f_record,0,sizeof(FIL));
return -1;
}
f_res = f_write(&f_record,"This is a test buffer,write to sd card!
",FILE_WRITE_BUFF_LEN,&file_write_position_point);
if (FR_OK != f_res)
{
printf("%s %d Record.txt write failed!
",__FILE__,__LINE__);
memset(&f_record,0,sizeof(FIL));
return -1;
}
f_lseek(&f_record,0);
f_res = f_read(&f_record,(void *)g_file_read_buff,FILE_READ_BUFF_LEN,&file_read_position_point);
if (FR_OK != f_res)
{
printf("%s %d Record.txt read failed!
",__FILE__,__LINE__);
memset(&f_record,0,sizeof(FIL));
return -1;
}
f_res = f_close(&f_record);
if (FR_OK != f_res)
{
printf("%s %d Record.txt close failed!
",__FILE__,__LINE__);
memset(&f_record,0,sizeof(FIL));
return -1;
}
printf("%s %d Record.txt = %s
",__FILE__,__LINE__,g_file_read_buff);
我的做法是下载程序到开发板后,关闭开发板电源,sd卡连pc,清除sd卡,然后再插上sd卡,然后打开开发板电源,串口一直连接,打开串口调试助手后,看到终端打印信息也正常。
,但是在sd卡中生成的文本文档文件中除了应当有的字符串外还有别的东西!!!
,不知道这些东西怎么会写入到我的文件里的?自己调了好久也没调通,求助原子哥及各位大神!!!
然后我换了一张卡,没这个问题。后来我把原来的SD卡格式化也解决了。
一周热门 更多>