Watchdog role: Due to the microcontroller work is often subject to interference from external electromagnetic fields, resulting in runaway program, and an endless loop, the normal operation of the program is interrupted, unable to work by the system microprocessor controlled, can cause The entire system is in a stagnant state and unexpected consequences occur. Therefore, considering the real-time monitoring of the operating state of the microcontroller, a module or chip specifically designed to monitor the running status of the microcontroller program is generated, which is commonly referred to as a “watchdogâ€. (watchdog). Two kinds of STM32F1** watchdogs: independent watchdog and window watchdog. The independent watchdog uses an independent clock (external low-speed clock LSI) and is suitable for applications where the watchdog is required to be able to operate completely independently of the main program and has a low time accuracy requirement. The principle is within a set period of time. Feed the dog on it. The window watchdog uses the system clock (APB1 clock frequency division), which is suitable for occasions such as storing important parameters when running out of the program monitor. The feeding time of the dog is within the range of the upper and lower limits (window). You can set the upper limit time (fixed lower limit) by setting related registers. It is not too early or too late to feed the dog. Equipped with the interrupt function WWDG_IRQHandler(void) that sets the status of the feed dog. 1. Cancel register write protection: IWDG_WriteAccessCmd(); 2. Set the independent watchdog prescaler to determine the clock: IWDG_SetPrescaler(); Understand the concept of frequency division: LSI clock frequency is 40K, if the prescaler coefficient is 4, then the frequency is 40/4 = 10K. The frequency division coefficient can choose 4, 8, 16, 32, 64, 128, 256 3. Set the watchdog reload value to determine the overflow time: IWDG_SetReload(); Maximum timeout = (IWDG_RLR register maximum) X Watchdog clock period 4. Enable watchdog: IWDG_Enable(); 5. The application feeds the dog: IWDG_ReloadCounter(); 1. Enable watchdog clock: RCC_APB1PeriphClockCmd(); 2. Set the frequency division factor: WWDG_SetPrescaler(); APB1 is 36MHz frequency division factor can choose 1,2,4,8. If the prescale factor is 8, then the frequency is 36000/(4096*8) = 1.098K 3. Set the window value: WWDG_SetWindowValue(); 4. Turn on early wake-up interrupts and group (optional): WWDG_EnableIT(); NVIC_Init(); 5. Enable watchdog: WWDG_Enable(); 6. Feed the dog: WWDG_SetCounter(); 7. Write interrupt service function WWDG_IRQHandler(); WWDG_Init(0X7F,0X5F,WWDG_Prescaler_8);//Counter value is 7F Window register is 5F Divisor factor 8