关于STM32 SD存储程序的一个问题
时间:10-02
整理:3721RD
点击:
以下是鄙人测试中的一个代码,用来将数据存储到SD中,现在的问题是,如果这段程序单独的在while(1)循环里,是可以一直存储数据的,但是一旦这段程序放下了if的条件语句下面,就无法将数据保存到SD卡中,调试程序发现这段存储程序无法运行完整,不知道是什么原因,不知有大神碰到类似情况或者能给个解答么。跪谢!
while(1)
{
f_mount(0,&fs);
sprintf((char *)file_name,"data%d.txt",num++);
res = f_open(&fnew, (char *)file_name, FA_CREATE_NEW | FA_WRITE );
f_close(&fnew);
printf("%d\n",res);
res = f_open(&fnew, (char *)file_name, FA_READ|FA_WRITE | FA_OPEN_ALWAYS );
res = f_lseek(&fnew,f_size(&fnew));
for(i=0;i<255;i++)
{
sprintf(RS232_buffconv,"%d ",RS232_buff);
if(res == FR_OK)
{
res = f_write(&fnew,RS232_buffconv,4,&bw);
}
}
f_close(&fnew);
f_mount(0, NULL);
}
while(1)
{
f_mount(0,&fs);
sprintf((char *)file_name,"data%d.txt",num++);
res = f_open(&fnew, (char *)file_name, FA_CREATE_NEW | FA_WRITE );
f_close(&fnew);
printf("%d\n",res);
res = f_open(&fnew, (char *)file_name, FA_READ|FA_WRITE | FA_OPEN_ALWAYS );
res = f_lseek(&fnew,f_size(&fnew));
for(i=0;i<255;i++)
{
sprintf(RS232_buffconv,"%d ",RS232_buff);
if(res == FR_OK)
{
res = f_write(&fnew,RS232_buffconv,4,&bw);
}
}
f_close(&fnew);
f_mount(0, NULL);
}