上电第一次初始化完成,连续创建Demo.TXT文件成功,返回FR_OK,带电状态不拔卡更改文件名为Demo1.TXT重新编译,再次单步运行到f_open函数是总是返回FR_DISK_ERR,单步发现在发送CMD17指令时返回0x04错误指令状态,如果将卡拔下再重新下载运行程序到f_open创建Demo1.TXT就可以返回FR_OK创建文件成功,求教高手这是什么原因造成的,是不是那里没有注意到。
贴段程序代码
if( _card_insert() == 0 )
{
printf("-- SD card detected OK \r\n");
}
else
{
printf("-- Please connect a SD card \r\n");
while( _card_insert() != 0 );
printf("-- SD card connection detected \r\n");
Delay(0xffffff);
}
f_mount(0,&fs);
res = f_open( &fsrc , "0:/Demo.TXT" , FA_CREATE_NEW | FA_WRITE);
if ( res == FR_OK )
{
/* Write buffer to file */
res = f_write(&fsrc, textFileBuffer, sizeof(textFileBuffer), &br);
printf("Demo.TXT successfully created \r\n");
/*close file */
f_close(&fsrc);
}
else if ( res == FR_EXIST )
{
printf("Demo.TXT created in the disk \r\n");
}
scan_files(path);
SD_TotalSize();
/* Infinite loop */
while (1){
} |