当前位置:网站首页>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);
};
}
边栏推荐
- Teach you how to install the latest version of mysql8.0 database on windows, nanny level teaching
- Have you grasped the most frequently asked question in the interview about massive data processing?
- mysql视图能不能创建索引
- On adding and subtracting dates
- Sword finger offer 13 Robot range of motion (BFS)
- selenium上传文件
- 育润多维发力慈善领域,勇抗企业公益大旗
- 第42期:MySQL 是否有必要多列分区
- 阿里云不同账号新旧服务器镜像迁移数据迁移同步
- [the sixth operation of modern signal processing]
猜你喜欢

Face recognition 4- research on Baidu commercial solutions

ISO 32000-2 国际标准7.7

Automatic vending machine

从一个被应用商店坑了的BUG说起

2022 spring summer collection koreano essential reshapes the vitality of fashion

Two controller layer interface authentication methods

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

selenium上传文件

分布式 | 几步快速拥有读写分离

Opencv+yolo-v3 for target tracking
随机推荐
VB.Net读写NFC Ntag标签源码
Web Scraping with Beautiful Soup for Data Scientist
【WebDriver】使用AutoIt上传文件
面试中问最常问的海量数据处理你拿捏了没?
R语言将距离矩阵输入给hclust函数进行层次聚类分析,method参数指定两个组合数据点间的距离计算方式、plot函数可视化层次聚类的树状图(dendrogram)
数字孪生能源系统,打造低碳时代“透视”眼
What is a SCM system? What are the advantages of a supply chain management system?
R language uses user-defined functions to write deep learning linear activation functions and visualize linear activation functions
How to use the chart control of the b/s development tool devextreme - customize the axis position?
Selenium key combination operation
mac安装php7.2
R language uses user-defined functions to write deep learning leaky relu activation functions and visualize leaky relu activation functions
Industry application of smart city based on GIS 3D visualization
基于STM32F103ZET6库函数串口实验
The R language inputs the distance matrix to the hclust function for hierarchical clustering analysis. The method parameter specifies the distance calculation method between two combined data points,
传承中华美德,关注中老年大健康,育润奶粉敬老情浓
Cross border independent station language Unicode to Hebrew
What is the function of MySQL cursors
SSH protocol learning notes
How MySQL queries character set codes of tables