STM32f103 看门狗使用
扫描二维码
随时随地手机看文章
//看门狗使用需要计算超时时间
// IAR 7.1
#ifndef __STM32_WDG_H__
#include "stm32f10x.h"
#define LSI_FREQ 40000
void stm32_wdg_init(void);
void stm32_wdg_enable(void);
void stm32_wdg_feed(void);
#endif
#include "stm32_wdg.h"
#include "stm32f10x_iwdg.h"
void stm32_wdg_init(void)
{
/*Enables write access to IWDG_PR and IWDG_RLR registers */
IWDG_WriteAccessCmd(IWDG_WriteAccess_Enable);
/*Set prescaler value*/
IWDG_SetPrescaler(IWDG_Prescaler_64);
/*Set reload value
Counter Reload Value = 250ms/IWDG counter clock period
= 250ms / (LSI/32)
= 0.25s / (LsiFreq/32)
= LsiFreq/(32 * 4)
= LsiFreq/128
*/
IWDG_SetReload(LSI_FREQ/32);
/*Download reload value to register*/
IWDG_ReloadCounter();
}
void stm32_wdg_enable(void)
{
IWDG_Enable();
}
void stm32_wdg_feed(void)
{
IWDG_ReloadCounter();
}