STM32f407内部看门狗的代码
时间: 2024-05-14 08:18:49 浏览: 12
以下是STM32F407内部看门狗(Watchdog)的初始化和启动代码:
```c
#include "stm32f4xx.h"
void WWDG_Init(uint8_t tr, uint8_t wr, uint32_t fprer)
{
/* check if the system has resumed from WWDG reset */
if (RCC_GetFlagStatus(RCC_FLAG_WWDGRST) != RESET)
{
/* clear the flag */
RCC_ClearFlag();
/* turn on LED2 */
STM_EVAL_LEDOn(LED2);
}
/* Enable the peripheral clock */
RCC_APB1PeriphClockCmd(RCC_APB1Periph_WWDG, ENABLE);
/* WWDG clock counter = (PCLK1 (42MHz)/4096)/8) = 1281 Hz (~780 us) */
WWDG_SetPrescaler(fprer);
/* Set Window value to 80; WWDG counter should be refreshed only when the counter
is below 80 (and greater than 64) otherwise a reset will be generated */
WWDG_SetWindowValue(wr);
/* Refresh WWDG counter every 780 us */
WWDG_Enable(tr);
}
int main(void)
{
/* WWDG configuration */
WWDG_Init(0x7F, 0x5F, WWDG_Prescaler_8);
while (1)
{
}
}
```
在上面的代码中,WWDG_Init() 函数用于初始化看门狗,并使用WWDG_Enable()函数启动它。在这里,看门狗的窗口值是0x5F,看门狗定时器初始值为0x7F。这意味着,如果我们在看门狗计数器到达0x5F之前不及时刷新它,系统将会重置。
相关推荐
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)