打印
[STM8]

STM8L单片机(STM8L101)独立看门狗(IWDG)使用注意事项

[复制链接]
5622|1
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
电子云图|  楼主 | 2014-5-18 10:14 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
本帖最后由 电子云图 于 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。

沙发
mmuuss586| | 2014-5-18 12:25 | 只看该作者
谢谢分享经验

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

11

主题

162

帖子

7

粉丝