一:打开看门狗的时钟
RCC_APB1PeriphClockCmd(RCC_APB1Periph_WWDG, ENABLE);
二:设置时钟分频
/* WWDG clock counter = (PCLK1 (42MHz)/4096)/8 = 1281 Hz (~780 us) */
WWDG_SetPrescaler(WWDG_Prescaler_8);
三:设置“下窗口”的值
WWDG_SetWindowValue(80);
四:使能打开看门狗
WWDG_Enable(127);//127强制转换为8进制为7f,去掉第6位,剩下3f,为最大值
此处注意,喂狗窗口的时间为36.6到49.9之间,超出这个时间,或者提前喂狗都会引起系统复位。
/* Enable WWDG and set counter value to 127, WWDG timeout = ~780 us * 64 = 49.92 ms
In this case the refresh window is: ~780 * (127-80) = 36.6ms < refresh window < ~780 * 64 = 49.9ms
*/
In this case the refresh window is: ~780 * (127-80) = 36.6ms < refresh window < ~780 * 64 = 49.9ms
*/