依据正点原子的FATFS 例程编写
能挂载但是无法写入
double imu=-32.12;
char tb[20];
sprintf(tb,"%lf",imu);
f_mount(fs[0],"0:",1); //挂载SD卡
while(res = f_mount(fs[0],"0:",1)) //挂载SD卡失败
{
printf("\r\nMount SD Card Error!");
delay_ms(500);
}
while(exf_getfree("0:",&total,&free)) //得到SD卡的总容量和剩余容量
{
printf("\r\nSD Card Fatfs Error!\r\n");
delay_ms(200);
LED0_Toggle;//DS0闪烁
}
mf_scan_files("0:");
FIL fil; //文件对象
UINT br; //f_read函数返回已读出的字节数
int size;
//打开一个只读的文件
f_open(&fil,"0:/imu1.txt",FA_WRITE);
f_write(&fil,tb,sizeof(tb),&bw);
f_close(&fil);
f_open(&fil,"0:/imu1.txt",FA_READ);
//移动打开的文件对象的文件读/写指针 0:指向文件开头
f_lseek(&fil,0);
size = f_size(&fil);
printf("%d\n",size);
char buff[size];
//从SD卡中读出数据
f_read(&fil,buff,size,&br);
//关闭文件
f_close(&fil);
printf("%s\n",buff);
printf("test");
////
//
//
结果如下
202 3-03-2218:54:17.829]
RX:BE中统志口LCDID:ffff
KAND ID:0xdc909556
total block num:4096
goodblocknum:4096
yalid block num:3809
NAND ID:0xdc909556
total blocknum:4096
good blocknum:4096
yalid block mum:3809
的0:/imul.txt
Otest