f_mount(0,&fs);
res_a = f_open(&file,"tes_super.txt",FA_OPEN_ALWAYS|FA_WRITE | FA_READ);
if (res_a == FR_OK)
{
printf("fsize1:%d\r\n",file.fsize);
f_lseek(&file,file.fsize);
printf("dd:%s \r\n","create file ok!");
do
{
res_a = f_write(&file,buf_super_char, super_char_num_n+1, &bw);
if(res_a)
{
printf("dd:%s \r\n","write error\r\n");
break;
}
printf("dd:%s \r\n","write ok");
}
while(bw<super_char_num_n+1);
}
f_close(&file);
delay_ms(2000);
f_mount(0,&fs);
res_a= f_open(&file,"tes_car.txt",FA_OPEN_ALWAYS|FA_WRITE | FA_READ);
if (res_a== FR_OK)
{
printf("fsize:%d\r\n",file.fsize);
f_lseek(&file,file.fsize);
printf("dd:%s \r\n","create2 file ok!");
do
{
res_a = f_write(&file,buf_car_move, car_move_num_n+1, &bw);
if(res_a)
{
printf("dd:%s \r\n","write2 error");
break;
}
printf("dd:%s \r\n","write2 ok\r\n");
}
while(bw<car_move_num_n+1);
}
f_close(&file);
delay_ms(2000);
写文件代码如上第一组往sd卡里存超声波测距数据,第二组测编码器脉冲。串口打印显示正常,文件存储成功。但是打开text文件的时候,有时候能打开,有时候会出现乱码,求助,帮忙解答一下原因,先谢过了。 |