新手入门
- 积分
- 18
- 金钱
- 18
- 注册时间
- 2020-5-21
- 在线时间
- 14 小时
|
20金钱
stm32移植了ucosⅢ,现在想每隔一段时间往SD卡写入数据,参考的原子软件定时器的教程,每次开启定时器就死机,求指点下怎么实现,是方法不对还是写的程序不对。程序如下:
void task1_task(void *p_arg)
{
u8 key,num;
OS_ERR err;
while(1)
{
key = KEY_Scan(0);
switch(key)
{
case WKUP_PRES: //μ±key_up°′ÏÂμÄ»°′ò¿a¶¨ê±Æ÷1
OSTmrStart(&tmr1,&err); //¿aÆô¶¨ê±Æ÷1
break;
case KEY1_PRES: //μ±key1°′Ï»°¾í1رն¨ê±Æ÷
OSTmrStop(&tmr1,OS_OPT_TMR_NONE,0,&err); //1رն¨ê±Æ÷1
break;
}
num++;
if(num==25) //ÿ500msLED0éá˸ò»′Î
{
num = 0;
LED0 = ~LED0;
}
OSTimeDlyHMSM(0,0,0,40,OS_OPT_TIME_PERIODIC,&err); //Ñóê±10ms
}
}
//¶¨ê±Æ÷1μÄ»Øμ÷oˉêy
void tmr1_callback(void *p_tmr, void *p_arg)
{
Write_Data();
LED1 = ~LED1;
}
uint8_t Write_Data()
{
OS_ERR err;
FRESULT res;
FIL fil;
DIR tdir;
UINT bww;
// u8 hum,tem;
char Con[60];
char name_buf[30];
CPU_SR_ALLOC();
RTC_Get();
sprintf(name_buf,"%s%0.2d%0.2d%0.2d%s","0:/DATA/", calendar.w_year,calendar.w_month,calendar.w_date,".txt");
sprintf(Con,"%0.2d:%0.2d/%s%d%s%d%s%d%s%d%s%d \r\n",calendar.hour,calendar.min,"Tem:",temperature,"/Hum:",humidity,"/Light:",lux,"/soil_humi:",soil_humi/100,"/soil_ph: ",soil_ph/10);
OSSchedLock(&err);
res = f_open(&fil, name_buf, FA_WRITE|FA_OPEN_ALWAYS);
// printf("%d\r\n",res);
if (res != FR_OK)
{
// printf("open succesed");
OSSchedUnlock(&err);
return 0;
}
res = f_lseek(&fil,fil.fsize);
res = f_write(&fil, Con, sizeof(Con), &bww);
printf("%d\r\n",res);
if (res != FR_OK)
{
OSSchedUnlock(&err);
return 0;
}
f_close(&fil);
OSSchedUnlock(&err);
return 1;
}
|
|