一般情况下开机如果第一次写数据成功连续写半天都不会卡死,但是也会出现长时间写数据卡死的情况,只是比较少见
经常出现的情况就是 初始化完毕第一次写数据成功 但是在rtc中断里写入一个u8 buff[120]的数据时经常第一次就卡死了
而且连续写成功和失败的几率 几乎各占一半吧
我用JTAG硬件仿真 程序死掉以后 总是停在
void HardFault_Handler(void)
{
/* Go to infinite loop when Hard Fault exception occurs */
while (1)
{
}
}
这里 不知道怎么回事???
[mw_shl_code=c,true] //**********************************************sd¿¨Ïà¹ØµÄÅäÖÃ***************************************
POINT_COLOR=RED;
my_mem_init(SRAMIN); //³õʼ»¯ÄÚ²¿ÄÚ´æ³Ø
printf("ÄÚ´æ³Ø³õʼ»¯Íê±Ï
");
while(SD_Init())//¼ì²â²»µ½SD¿¨
{
static int a=0;
LCD_ShowString(30,150,200,16,16,"SD Card Error!");
delay_ms(500);
LCD_ShowString(30,150,200,16,16,"Please Check! ");
delay_ms(500);
printf(" ûÓмì²âµ½sd¿¨Çë²åÈësd¿¨
");
a++;
if(a>=10)
{
printf("ûÓмì²âµ½sd¿¨Çë²åÈësd¿¨
");
SDcardFlage=pullOutSDcard;
break;
}
}
if(SDcardFlage==insertedSDcard)
{
show_sdcard_info(); //´òÓ¡SD¿¨Ïà¹ØÐÅÏ¢
POINT_COLOR=BLUE; //ÉèÖÃ×ÖÌåΪÀ¶É«
//¼ì²âSD¿¨³É¹¦
LCD_ShowString(30,150,200,16,16,"SD Card OK ");
LCD_ShowString(30,170,200,16,16,"SD Card Size: MB");
LCD_ShowNum(30+13*8,170,SDCardInfo.CardCapacity>>20,5,16);//ÏÔʾSD¿¨ÈÝÁ¿
}
exfuns_init(); //ΪfatfsÏà¹Ø±äÁ¿ÉêÇëÄÚ´æ
printf("ÉêÇëfatfsÄÚ´æÍê±Ï
");
if(SDcardFlage==insertedSDcard)
{
res=f_mount(fs[0],"0:",1); //¹ÒÔØSD¿¨
printf("sd_return %d
",res);
printf("¹ÒÔØsd¿¨Íê±Ï
");
}
LCD_Fill(30,150,240,150+16,BLACK); //Çå³ýÏÔʾ
if(SDcardFlage==insertedSDcard)
{
while(exf_getfree("0",&total,&free)) //µÃµ½SD¿¨µÄ×ÜÈÝÁ¿ºÍÊ£ÓàÈÝÁ¿
{
LCD_ShowString(30,150,200,16,16,"SD Card Fatfs Error!");
delay_ms(200);
LCD_Fill(30,150,240,150+16,BLACK); //Çå³ýÏÔʾ
delay_ms(200);
}
POINT_COLOR=BLUE;//ÉèÖÃ×ÖÌåΪÀ¶É«
LCD_ShowString(30,150,200,16,16,"FATFS OK!");
LCD_ShowString(30,170,200,16,16,"SD Total Size: MB");
LCD_ShowString(30,190,200,16,16,"SD Free Size: MB");
LCD_ShowNum(30+8*14,170,total>>10,5,16); //ÏÔʾSD¿¨×ÜÈÝÁ¿ MB
LCD_ShowNum(30+8*14,190,free>>10,5,16); //ÏÔʾSD¿¨Ê£ÓàÈÝÁ¿ MB
}
//**********************************************sd¿¨Ïà¹ØµÄÅäÖÃ***************************************
[/mw_shl_code]
[mw_shl_code=applescript,true]//***********************************ÔÚsd¿¨´´½¨Îļþ**********************************
if(SDcardFlage==insertedSDcard)
{
RTC_Get();//¸üÐÂʱ¼ä
printf("´´½¨Îļþʱ¼ä:%04d-%02d-%02d %02d:%02d
",calendar.w_year,calendar.w_month,
calendar.w_date,calendar.hour,calendar.min);//´òÓ¡´´½¨ÎļþµÄʱ¼ä
sprintf((char*)f_namebuf,"0:/%04d%02d%02d%02d%02d.txt",calendar.w_year,calendar.w_month,
calendar.w_date,calendar.hour,calendar.min); //½«Ê±¼äµÄÕûÐÍÊý¾Ýת»¯³É×Ö·û´®²¢±£´æµ½Êý×éÖÐ
printf("ÎļþÃû³Æ:");
printf((char*)f_namebuf);//´òÓ¡³ö´´½¨ÎļþµÄÃû³Æ
printf("
");
res=f_open (&fil,(char*)f_namebuf, FA_CREATE_ALWAYS|FA_WRITE);//ÒÔʱ¼äÃüÃûÎļþ²¢´´½¨ÎļþÒÔдÈëģʽ´ò¿ª
res=f_puts((char *)f_namebuf,&fil);//ÔÚÎļþÀïдÈëʱ¼äµÄ×Ö·û´®
res=f_close(&fil);//¹Ø±ÕÎļþ
SDcardFlage=insertedSDcard;//±ê־λ¸ºÖµ±íʾÒѾ­²åÈësd¿¨
//printf("The number 'num' is %d and the string 'str' is %s.
" , 115, str);
}
else
{
printf("ûÓмì²âµ½sd¿¨²»´´½¨Îļþ
");
SDcardFlage=pullOutSDcard;//±ê־λ¸ºÖµ±íʾÒѾ­°Î³ösd¿¨
}
//***********************************ÔÚsd¿¨´´½¨Îļþ**********************************[/mw_shl_code]
以上是初始化代码
以下是rtc每隔两分钟写入的代码
[mw_shl_code=applescript,true] if(RTCtimeContTemp>=120)//Ô­Öµ120
{
u8 i;
RTCtimeContTemp=0;
//Ïòsd¿¨Ð´ÈëѹÁ¦ÇúÏßÊý×é´æµÄÊý
if(SDcardFlage==insertedSDcard)//Èç¹û²åÈësd¿¨
{
FIL fil;
u8 res;
res=f_open(&fil,(char*)f_namebuf,FA_WRITE);//ÒÑдµÄ·½Ê½´ò¿ªÎļþ
res=f_lseek(&fil,fil.fsize);//Òƶ¯ÎļþÖ¸Õëµ½ÎļþÊý¾ÝµÄβ²¿
printf("´ò¿ªÎļþÖ¸ÕëºóÒÆ
");
for(i=0;i<120;i++)
{
//printf("%d
",i);
sprintf((char*)f_TXbuff,"%03d ",save_temp_perSec);//½«Êý×éÀï±£´æµÄѹÁ¦±äÁ¿×ª»¯³É×Ö·û´®²¢±£´æÔÚÊý×éÖÐ
res=f_puts((char*)f_TXbuff,&fil);//¾­ÊýдÈëµ½sd¿¨µÄtxtÎļþÖÐ
}
res=f_close(&fil);//¹Ø±Õ±£´æÎļþ
printf("Íê³ÉtxtÎļþдÈë
");
}
else printf("ûÓÐsd¿¨²»Ð´Îļþ
");
}[/mw_shl_code]
一周热门 更多>