独立看门狗(IWDG)由专用的内部低速时钟(LSI)驱动,能够在低功耗模式下正常工作。
根据寄存器描述,IWDG最大时间可以是(0xFFF/(32K/512))=65.52s
代码如下:
#define FEED_IWDG() {R32_IWDG_KR=0xAAAA;} //需要定时调用喂狗
看门狗初始化
void IWDG_Enable() { R32_IWDG_KR=0x5555;//解除IWDG保护 R32_IWDG_CFG |= (7<<12);//32K分频512,时钟62.5Hz R32_IWDG_CFG &=0xFFFFF000; R32_IWDG_CFG |=0xFFF;//看门狗时间约65s(0xFFF/(32K/512)) R32_IWDG_KR=0xCCCC; //开启IWDG保护 }
操作演示
void main() { IWDG_Enable(); //使能IWDG PRINT("R32_IWDG_CFG = %x\r\n", R32_IWDG_CFG); while(1){ FEED_IWDG(); //喂狗 } }
如果不喂狗,缩减狗时间,操作如下:
void IWDG_Enable() { R32_IWDG_KR=0x5555;//解除IWDG保护 R32_IWDG_CFG |= (7<<12);//32K分频512,时钟62.5Hz R32_IWDG_CFG &=0xFFFFF000; R32_IWDG_CFG |=0x10;//看门狗时间约256ms(0x10/(32K/512)) R32_IWDG_KR=0xCCCC; } void main() { IWDG_Enable(); //使能看门狗 PRINT("R32_IWDG_CFG = %x\r\n", R32_IWDG_CFG); while(1){ // FEED_IWDG(); } }
运行结果如下:
标签:Enable,CH592,CFG,void,看门狗,IWDG,R32 From: https://www.cnblogs.com/debugdabiaoge/p/17580033.html