本帖最后由 电子云图 于 2014-5-18 10:16 编辑
最近在用STM8L单片机(STM8L101)做一个低功耗的产品,在调试独立看门狗(IWDG)时,我先用库(V1.2.0)提供的例程进行实验,发现喂不了狗,后来在将IWDG_Enable();函数移到static void IWDG_Config(void)的最前面就OK了,如下图
/*原文件*/
static void IWDG_Config(void){
/* IWDG timeout equal to 214 ms (the timeout may varies due to LSI frequency
dispersion) */
/* Enable write access to IWDG_PR and IWDG_RLR registers */
IWDG_WriteAccessCmd(IWDG_WriteAccess_Enable);
/* IWDG configuration: IWDG is clocked by LSI = 38KHz */
IWDG_SetPrescaler(IWDG_Prescaler_32);
/* IWDG timeout equal to 214.7 ms (the timeout may varies due to LSI frequency dispersion) */
/* IWDG timeout = (RELOAD_VALUE + 1) * Prescaler / LSI
= (254 + 1) * 32 / 38 000
= 214.7 ms */
IWDG_SetReload((uint8_t)RELOAD_VALUE);
/* Reload IWDG counter */
IWDG_ReloadCounter();
/* Enable IWDG (the LSI oscillator will be enabled by hardware) */
IWDG_Enable();
}
/*更改后*/
static void IWDG_Config(void)
{
/* Enable IWDG (the LSI oscillator will be enabled by hardware) */
IWDG_Enable();
/* IWDG timeout equal to 214 ms (the timeout may varies due to LSI frequency
dispersion) */
/* Enable write access to IWDG_PR and IWDG_RLR registers */
IWDG_WriteAccessCmd(IWDG_WriteAccess_Enable);
/* IWDG configuration: IWDG is clocked by LSI = 38KHz */
IWDG_SetPrescaler(IWDG_Prescaler_32);
/* IWDG timeout equal to 214.7 ms (the timeout may varies due to LSI frequency dispersion) */
/* IWDG timeout = (RELOAD_VALUE + 1) * Prescaler / LSI
= (254 + 1) * 32 / 38 000
= 214.7 ms */
IWDG_SetReload((uint8_t)RELOAD_VALUE);
/* Reload IWDG counter */
IWDG_ReloadCounter();
}
在此发此贴,希望后面的人不要走弯路,同时希望香主把情况反映给STM, 让其更改此BUG. thanks ---- Happy every day。
|