At first, LED1 is on and LED2 is off. If KEY1 is pressed at regular intervals, LED2 will flash continuously because the independent watchdog resets the system. If KEY1 is pressed intermittently, LED2 will not flash, indicating that it has not been reset.
experiment platform:
Color screen development board based on STM32F103C8T6
Steps:
1) Write 0X5555 to IWDG_KR.
Through this step, we cancel the write protection of IWDG_PR and IWDG_RLR, so that these two registers can be operated later.
Set the values of IWDG_PR and IWDG_RLR.
These two steps set the watchdog frequency division coefficient and the reload value. From this, we can know the feeding time of the watchdog (that is
, the watchdog overflow time), which is calculated as follows:
Tout=((4×2^prer) ×rlr)/40
, where Tout is the watchdog overflow time (in ms); prer is the watchdog clock prescaler value (IWDG_PR value),
ranging from 0 to 7; rlr is the watchdog reload value (IWDG_RLR value);
for example, if we set the prer value to 4 and the rlr value to 625, we can get Tout=64×625/40=1000ms, so
the watchdog overflow time is 1s. As long as you write 0XAAAA to IWDG_KR once within one second, the watchdog will not be reset (of course, writing multiple times is also possible). Here we need to remind everyone that the watchdog clock is not an accurate
40Khz, so it is best not to feed the dog too late, otherwise, the watchdog may be reset.
2) Write 0XAAAA to IWDG_KR.
This command will cause STM32 to reload the value of IWDG_RLR into the watchdog counter. This command can also be used
to feed the watchdog.
3) Write 0XCCCC to IWDG_KR.
This command starts the STM32 watchdog. Note that once IWDG is enabled, it cannot be turned off! If you want to turn it off
, you can only restart it, and you cannot turn on IWDG after restarting, otherwise the problem will remain. So here I remind you that if you don’t
use IWDG, don’t turn it on to avoid trouble.
Through the above 3 steps, we can start the STM32 watchdog. After enabling the watchdog,
you must feed the watchdog at intervals in the program, otherwise it will cause the program to reset. Using this, we use an LED light to indicate
whether the program is restarted to verify the independent watchdog of STM32.
Part of the program code:
#ifndef WATCHDOG_H
#define WATCHDOG_H
void WatchDog_Init(u8, u16);//Declare the watchdog initialization function
void WatchDog_Feed(void);//Declare the dog feeding function
#endif
#include "common.h"
#include "watchdog.h"
//Watchdog initialization, parameters: prer-frequency division, reld-counter reload value
void WatchDog_Init(u8 prer, u16 reld)
{
}
//Feed the dog
void WatchDog_Feed(void)
{
}
This code has two functions. void IWDG_Init(u8 prer, u16 rlr) is the independent watchdog initialization function, which is to
initialize the independent watchdog according to the steps described above. This function has two parameters, which are used to set the pre-scaling number and the reload
register value. Through these two parameters, you can roughly know the time period of the watchdog reset. The calculation method
is described in detail above, so I won’t say more here.
void IWDG_Feed(void) function, this function is used to feed the dog, because the STM32 dog feeding only needs to write
0XAAAA to the key value register,
#include
#include"common.h"
#include"led.h"
#include"key.h"
#include"watchdog.h"
int main(void)
{
}
Previous article:STM32 UART4 UART5
Next article:STM32 recognition rate of 1.8V peripheral devices (without level conversion)
Recommended ReadingLatest update time:2024-11-16 20:56
- Popular Resources
- Popular amplifiers
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- Innolux's intelligent steer-by-wire solution makes cars smarter and safer
- 8051 MCU - Parity Check
- How to efficiently balance the sensitivity of tactile sensing interfaces
- What should I do if the servo motor shakes? What causes the servo motor to shake quickly?
- 【Brushless Motor】Analysis of three-phase BLDC motor and sharing of two popular development boards
- Midea Industrial Technology's subsidiaries Clou Electronics and Hekang New Energy jointly appeared at the Munich Battery Energy Storage Exhibition and Solar Energy Exhibition
- Guoxin Sichen | Application of ferroelectric memory PB85RS2MC in power battery management, with a capacity of 2M
- Analysis of common faults of frequency converter
- In a head-on competition with Qualcomm, what kind of cockpit products has Intel come up with?
- Dalian Rongke's all-vanadium liquid flow battery energy storage equipment industrialization project has entered the sprint stage before production
- Allegro MicroSystems Introduces Advanced Magnetic and Inductive Position Sensing Solutions at Electronica 2024
- Car key in the left hand, liveness detection radar in the right hand, UWB is imperative for cars!
- After a decade of rapid development, domestic CIS has entered the market
- Aegis Dagger Battery + Thor EM-i Super Hybrid, Geely New Energy has thrown out two "king bombs"
- A brief discussion on functional safety - fault, error, and failure
- In the smart car 2.0 cycle, these core industry chains are facing major opportunities!
- The United States and Japan are developing new batteries. CATL faces challenges? How should China's new energy battery industry respond?
- Murata launches high-precision 6-axis inertial sensor for automobiles
- Ford patents pre-charge alarm to help save costs and respond to emergencies
- New real-time microcontroller system from Texas Instruments enables smarter processing in automotive and industrial applications
- bq40z50 series thermistor resistance coefficient calculator
- How should a fast charging decoy be evaluated?
- The hierarchical wordline structure can improve the SRAM read and write speed and reduce the circuit dynamic power consumption
- Bluehive Bluetooth headset charging case disassembly
- You can buy a robot dog for 1,500 yuan. It was made by a Nanjing University alumnus. It won't break if you step on it.
- What is your career plan for electronic engineering?
- The Differences and Working Principles of Digital Oscilloscopes and Analog Oscilloscopes
- TMS320F28335 ADC Learning Notes
- RGB Hexagonal Keyboard
- I am a newbie, where can I find the required package?