STM32f103 看门狗使用 -
[导读]//看门狗使用需要计算超时时间// IAR 7.1#ifndef __STM32_WDG_H__#include "stm32f10x.h"#define LSI_FREQ 40000void stm32_wdg_init(void);void stm32_wdg_enable(void);void stm32_wdg_feed(void);#endif#include
//看门狗使用需要计算超时时间
本文引用地址: http://www.21ic.com/app/mcu/201807/780690.htm
// 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();
}
查看评论 回复
"STM32f103 看门狗使用 -"的相关文章
- 上一篇:单片机的魅力---红外遥控
- 下一篇:定时器计数器的应用提高 -