|
发表于 2017-4-9 14:58:08
|
显示全部楼层
最近用103的板子+SD卡,做一个数据采集的东西,每5s中写一次数据,每次20K写入,采集一会后就卡死了,正在找问题。
下面附上我的代码:
void Task_WriteToSD(void)
{
if (buffer1IsFull == TRUE)
{
printf("\\nbuffer1 is full\\t\\n");
// printf("\\n写入前的时间是\\t%d\\n", time1=bsp_GetRunTime());
time1=bsp_GetRunTime();
res = f_open(&fdst, "demo.TXT", FA_OPEN_ALWAYS | FA_WRITE);
printf("\\nfile size is %d\\n",f_size(&fdst));
/* Move to end of the file to append data */
res = f_lseek(&fdst, f_size(&fdst));
res = f_write(&fdst, s_tToSDBuffer1, sizeof(s_tToSDBuffer1), &bw); //将缓冲区的数据写到文件中
memset(s_tToSDBuffer1,0,sizeof(s_tToSDBuffer1));
f_close(&fdst);
// printf("\\n写入后时间是\\t%d\\n", time2=bsp_GetRunTime());
time2=bsp_GetRunTime();
printf("\\n共计用时:%d\\n",time2-time1);
buffer1IsFull = FALSE;
}
if (buffer2IsFull == TRUE)
{
printf("\\nbuffer2 is full\\t\\n");
time1=bsp_GetRunTime();
// printf("\\n写入前的时间是\\t%d\\n", time1=bsp_GetRunTime());
res = f_open(&fdst, "demo.TXT", FA_OPEN_ALWAYS | FA_WRITE);
printf("\\nfile size is %d\\n",f_size(&fdst));
/* Move to end of the file to append data */
res = f_lseek(&fdst, f_size(&fdst));
res = f_write(&fdst, s_tToSDBuffer2, sizeof(s_tToSDBuffer2), &bw); //将缓冲区的数据写到文件中
memset(s_tToSDBuffer2,0,sizeof(s_tToSDBuffer2));
f_close(&fdst);
time2=bsp_GetRunTime();
// printf("\\n写入后时间是\\t%d\\n", time2=bsp_GetRunTime());
printf("\\n共计用时:%d\\n",time2-time1);
buffer2IsFull = FALSE;
}
} |
|