当前位置:首页 > 单片机 > 单片机
[导读]//看门狗使用需要计算超时时间// 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

//看门狗使用需要计算超时时间

// 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();
}


本站声明: 本文章由作者或相关机构授权发布,目的在于传递更多信息,并不代表本站赞同其观点,本站亦不保证或承诺内容真实性等。需要转载请联系该专栏作者,如若文章内容侵犯您的权益,请及时联系本站删除( 邮箱:macysun@21ic.com )。
换一批
延伸阅读
关闭