本帖最后由 dsoyy 于 2010-4-10 14:44 编辑
xfcjava2,
void test_fatfs(void)
{
FATFS fs;
DSTATUS stat = 0;
FRESULT res; //文件系统返回信息
FIL file;
stat = disk_initialize(1);//SD_card_init();
Uart_Printf("%d\n",stat);
Write_SD("data.txt","12345",2);
while(1);
}
void Write_SD(const char *write_file,const void *buffer,UINT count)
{
FATFS fs;
FIL fil;
U32 bw;
FRESULT res; //文件系统返回信息
f_mount(1,&fs);//注册一个文件系统
res=f_open(&fil,write_file,FA_OPEN_ALWAYS|FA_WRITE);//建立文件的文件名最长8个字节
Uart_Printf("%d\n",res);
if(res!=FR_OK)
{
Uart_Printf("文件不能写!!!\r\n");
return;
}
res=f_lseek(&fil,fil.fsize);
res=f_write(&fil,buffer,count,&bw);
f_close(&fil);
f_mount(1, NULL);
}
void Write_SD(const char *write_file,const void *buffer,UINT count)
函数中的Uart_Printf("%d\n",res);为13,说明FS初始化没成功
FR_NO_FILESYSTEM /* 13*/ |