当前位置:网站首页>Function independent watchdog (iwdg) experiment based on stm32f103zet6 Library
Function independent watchdog (iwdg) experiment based on stm32f103zet6 Library
2022-06-29 17:46:00 【It's Beichen bupiacra】
be based on STM32F103ZET6 Library function independent watchdog (IWDG) experiment
STM32 Inside I brought it with me 2 A watchdog : Independent watchdog (IWDG) And the window watchdog (WWDG), Here we only introduce the independent watchdog , We will press the button WK_UP Feed the dog , Then pass too DS0 Prompt reset status .
STM32 Introduction to independent watchdog
STM32 The independent watchdog consists of an internal specialized 40Khz Low speed clock drive , Even if the master clock fails , It's still It works . It should be noted here that the clock of the independent watchdog is an internal RC The clock , So it's not accurate 40Khz, It is stay 30~60Khz A variable clock between , It's just that when we estimate , With 40Khz To calculate the frequency of , see The door dog is not very precise about the time , therefore , The clock is a little off , All are acceptable .
Single chip microcomputer system in the external interference will appear under the phenomenon of program running, leading to the emergence of dead cycle , The watchdog circuit is designed to avoid This happens . The role of a watchdog is to ( Through the timer counter ) No dog feed signal received ( Express MCU It's gone ), The processor can reset and restart automatically ( Send a reset signal ).
Independent watchdog related library functions and definitions are distributed in the file stm32f10x_iwdg.h and stm32f10x_iwdg.c in
1. Cancel register write protection ( towards IWDG_KR write in 0X5555)
Through this step , We cancel IWDG_PR and IWDG_RLR Write protection for , So that the two registers can be operated later , Set up IWDG_PR and IWDG_RLR Value . The implementation function in the library function is :
IWDG_WriteAccessCmd(IWDG_WriteAccess_Enable);
2. Set the prescaler factor and reload value of the independent watchdog
The function of setting the frequency division coefficient of the watchdog is :
void IWDG_SetPrescaler(uint8_t IWDG_Prescaler); // Set up IWDG Prescaled value
The function to set the watchdog reload value is :
void IWDG_SetReload(uint16_t Reload); // Set up IWDG Reload value
Set the frequency division coefficient of the good looking dog prer And reload load value can be used to know the feeding time of the watchdog ( That is, the watchdog overflow Out time ), The time is calculated as :
Tout=((4×2^prer) ×rlr) /40
among Tout Overflow time for watchdog ( Unit is ms);prer Pre frequency the watchdog clock (IWDG_PR value ), The scope is 0~7;rlr Load value for the watchdog (IWDG_RLR Value )
For example, we set prer The value is 4,rlr The value is 625, Then you can get Tout=64×625/40=1000ms, such , The watchdog's overflow time is 1s, As long as you're in a second , Once I wrote 0XAAAA To IWDG_KR, No Will cause the watchdog to reset ( Of course, writing multiple times is OK ). What we need to remind you of here is , The watchdog clock is not accurate Yes 40Khz, So when you feed the dog , It's better not to be too late , otherwise , There is a possibility of watchdog reset .
3. Load count value feed dog ( towards IWDG_KR write in 0XAAAA)
The function in the library function that overloads the count value is :
IWDG_ReloadCounter(); // according to IWDG Reload the value of the load register IWDG Counter
Through this sentence , Will make STM32 Reload IWDG_RLR To the watchdog counter . That is to realize the feeding operation of the independent watchdog .
4. Start the watchdog ( towards IWDG_KR write in 0XCCCC)
The function to start the independent watchdog in the library function is :
IWDG_Enable(); // Can make IWDG
Through this sentence , To start up STM32 The watchdog . Be careful IWDG Once enabled , It can't be shut down again ! Want to close close , Can only restart , And it can't be turned on after restart IWDG, Otherwise, the problem remains , So I'm here to remind you , If you don't use IWDG Words , Just don't open it , Avoid trouble .
After configuring the watchdog ,DS0 Will always be bright , If WK_UP Press the key , Just feed the dog , as long as WK_UP Keep pressing , The watchdog will never reset , keep DS0 Chang liang of , Once the watchdog set overflow time is exceeded (Tout) Not yet , Then it will cause the program to restart , This will lead to DS0 Put it out once .
Hardware design
1) Indicator light DS0
2) WK_UP Key
3) Independent watchdog
software design
wdg.c
#include "wdg.h"
// Initialize the independent watchdog
//prer: Frequency division number :0~7( Only low 3 Bit effective !)
// Division factor =4*2^prer. But the maximum can only be 256!
//rlr: Reload register values : low 11 Bit effective .
// Time calculation ( Probably ):Tout=((4*2^prer)*rlr)/40 (ms).
void IWDG_Init(u8 prer,u16 rlr)
{
IWDG_WriteAccessCmd(IWDG_WriteAccess_Enable); // Enable on register IWDG_PR and IWDG_RLR Write operations for
IWDG_SetPrescaler(prer); // Set up IWDG Prescaled value : Set up IWDG The prescaled value is 64
IWDG_SetReload(rlr); // Set up IWDG Reload value
IWDG_ReloadCounter(); // according to IWDG Reload the value of the load register IWDG Counter
IWDG_Enable(); // Can make IWDG
}
// Hello, the independent watchdog
void IWDG_Feed(void)
{
IWDG_ReloadCounter(); //reload
}
because STM32 To feed a dog, you only need to write... To the key value register Enter into 0XAAAA that will do , That is to call IWDG_ReloadCounter() function
wdg.h
#ifndef __WDG_H
#define __WDG_H
#include "sys.h"
void IWDG_Init(u8 prer,u16 rlr);
void IWDG_Feed(void);
#endif
main.c
#include "led.h"
#include "delay.h"
#include "key.h"
#include "sys.h"
#include "usart.h"
#include "wdg.h"
int main(void)
{
delay_init(); // Delay function initialization
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2); // Set up NVIC Interrupt grouping 2:2 Bit preemption priority ,2 Bit response priority
uart_init(115200); // The serial port is initialized to 115200
LED_Init(); // Initialization and LED Connected hardware interface
KEY_Init(); // Key initialization
delay_ms(500); // Let people see
IWDG_Init(4,625); // And the frequency division number is 64, The overload value is 625, The overflow time is 1s
LED0=0; // Lighten up LED0
while(1)
{
if(KEY_Scan(0)==WKUP_PRES)
{
IWDG_Feed(); // If WK_UP Press down , Then feed the dog
}
delay_ms(10);
};
}
边栏推荐
- Web Scraping with Beautiful Soup for Data Scientist
- 【WebDriver】使用AutoIt上传文件
- OpenFeign使用步骤 轮询策略与权重 log4j使用 openFeign拦截器的配置
- The soft youth under the blessing of devcloud makes education "smart" in the cloud
- Visio标注、批注位置
- 关于日期相加减问题
- Online sql to CSV tool
- Analyze the implementation principle of zero copy mechanism, applicable scenarios and code implementation
- 剑桥大学教授:经常吃早餐害处多,很危险 - 知乎
- 小程序容器是什么技术?能助力物联网企业红海突围?
猜你喜欢

两种Controller层接口鉴权方式

位图的详细介绍及模拟实现

Mysql database literacy, do you really know what a database is

Analyze the implementation principle of zero copy mechanism, applicable scenarios and code implementation

布隆过滤器:

力扣每日一题 06.29 两数相加

如何使用B/S开发工具DevExtreme的图表控件 - 自定义轴位置?

DevCloud加持下的青软,让教育“智”上云端

ISO 32000-2 国际标准7.7

How to solve the 2003 error of MySQL in Linux
随机推荐
mysql在linux中2003错误如何解决
跨境独立站语言unicode转希伯来语
R语言使用glm函数构建泊松对数线性回归模型处理三维列联表数据构建饱和模型、使用exp函数和coef函数获取模型所有变量的事件密度比(Incidence Density Ratio,IDR)并解读
Set double click to run the jar file
国外LEAD赚钱,做个网站真的很简单
关于日期相加减问题
What is the function of MySQL cursors
Professor of Cambridge University: eating breakfast often is harmful and dangerous. - you know what
Use SSH to pull codes
Teach you how to install the latest version of mysql8.0 database on windows, nanny level teaching
Visual Studio插件CodeRush正式发布v22.1——优化调试可视化工具
第42期:MySQL 是否有必要多列分区
测试dble split功能执行+导入耗时shell脚本参考
The soft youth under the blessing of devcloud makes education "smart" in the cloud
使用autoIt 上传文件
SRM系统是什么系统?如何应用SRM系统?
R语言使用自定义函数编写深度学习Leaky ReLU激活函数、并可视化Leaky ReLU激活函数
MySQL触发器如何创建与删除
分布式 | 几步快速拥有读写分离
Visual studio plug-in coderush officially released v22.1 -- visual tool for optimizing debugging