If the configuration is not to cause an interrupt if the dog is not fed within a certain period of time, it will not cause the microcontroller to reset but will enter the watchdog interrupt.
When an interrupt is caused, the interrupt function is entered, and then exits and continues to execute from the place just entered. It should be noted that at this time, the watchdog counter is no longer decremented, that is, even if the dog is not fed now, the watchdog interrupt will not be caused. At this time, the program is equivalent to lacking the watchdog function. If the program runs away again during the next operation, it will really "let the program run for a while." At this point, it seems that the watchdog interrupt function is useless. However, Ration thought of a wonderful use of the watchdog interrupt. We can do something very urgent in the interrupt function (for example, turn off the power of the water heater), and then use the software reset function to reset the microcontroller. In this way, not only can the microcontroller be reset, but it can also play a multi-layer protection role.
Let's make an example below. After the watchdog interrupt is turned on, let the microcontroller send the character 'A' to the serial port at a certain interval. In the watchdog interrupt function, let the microcontroller send the character 'B' to the serial port. In this way, open the serial port debugging assistant and you can see the experimental results.
Create a new project with the structure shown below:
For an introduction to the uart.c file, please see Chapter 4.
The wdt.c file and wdt.h file are the same as those in Section 6.3.
In the main.c file, enter the following code:
#include "lpc11xx.h"
#include "wdt.h"
#include "uart.h"
void delay(void)
{
uint16_t i,j;
for(i=0;i<5000;i++)
for(j=0;j<280;j++);
}
/******************************************/
/* Function: Watchdog interrupt service function */
/* Description: When the MOD value is set to 0x01, if it is not timely*/
/* Feed the dog, and this interrupt function will be entered. */
/******************************************/
void WDT_IRQHandler(void)
{
LPC_WDT->MOD &= ~(0x1<<2); // Clear the watchdog timeout flag WDTOF
// Below you can write what you want to do when the watchdog interrupt occurs
UART_send_byte('B');
delay(); //Wait for data to be sent
NVIC_SystemReset();
}
int main()
{
UART_init(9600);
WDT_Enable(0); // Initialize the watchdog and feed it within 1 second
NVIC_EnableIRQ(WDT_IRQn);
while(1)
{
delay();
//WDTFeed();
UART_send_byte('A');
}
}
Line 23, starting from the main function.
Line 25 initializes the serial port baud rate to 9600. (For a detailed description of this function, see Chapter 4.)
Line 26, turn on the watchdog.
Line 27, enable NVIC watchdog interrupt.
Line 28 enters an infinite while loop and sends the character 'A' to the serial port at a certain interval.
Lines 15 to 22 define the serial port interrupt service function.
Line 17, write 0 to bit 2 of the WDMOD register to clear the watchdog timeout flag WDTOF. (If this bit is not cleared, you will not be able to exit after entering the interrupt function.)
Line 19 sends the character 'B' to the serial port.
Line 20, wait for the character 'B' to be sent. (Without this delay, the microcontroller will not successfully send the data and will execute the next sentence to reset the microcontroller.)
Line 21, reference the reset function to reset the microcontroller.
Reset function: NVIC_SystemReset()
#define SCB_AIRCR_VECTKEY_Pos 16
#define SCB_AIRCR_SYSRESETREQ_Pos 2
#define SCB_AIRCR_SYSRESETREQ_Msk (1UL << SCB_AIRCR_SYSRESETREQ_Pos)
__STATIC_INLINE void NVIC_SystemReset(void)
{
__DSB();
SCB->AIRCR = ((0x5FA << SCB_AIRCR_VECTKEY_Pos) | SCB_AIRCR_SYSRESETREQ_Msk);
__DSB();
while(1);
}
This function is a software reset of the microcontroller, located in the core_cm0.h file, we can use it directly. Just include the lpc11xx.h file in the header file.
This function uses the DSB instruction and the AIRCR register.
DSB instruction: Data synchronization isolation instruction, used to wait for all previous instructions to be completed.
SCB->AIRCR = ((0x5FA << SCB_AIRCR_VECTKEY_Pos) | SCB_AIRCR_SYSRESETREQ_Msk);
Combined with the register definition, it can be seen that line 8 of the function writes 0x05FA to bit31:16 and then writes 1 to bit2.
Line 10 waits for reset.
Previous article:LPC1114 watchdog_window watchdog
Next article:LPC1114 watchdog_reset
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- LED chemical incompatibility test to see which chemicals LEDs can be used with
- Application of ARM9 hardware coprocessor on WinCE embedded motherboard
- What are the key points for selecting rotor flowmeter?
- LM317 high power charger circuit
- A brief analysis of Embest's application and development of embedded medical devices
- Single-phase RC protection circuit
- stm32 PVD programmable voltage monitor
- Introduction and measurement of edge trigger and level trigger of 51 single chip microcomputer
- Improved design of Linux system software shell protection technology
- What to do if the ABB robot protection device stops
- 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
- Sandia Labs develops battery failure early warning technology to detect battery failures faster
- How long have you not spent the Lantern Festival at home?
- [Beetle ESP32-C3 Review] Part 2: vscode+idf+oled running through
- How to debug a 50Hz notch filter
- Protection processing circuit in IoT system and equivalent circuit of HF RFID reader
- EVAL-M3-TS6-665PN development board circuit structure and features
- 51 MCU falling edge trigger
- Reverse recovery process of rectifier diode
- Low-level error: ESP32 official routine compilation failed just because the folder name uses spaces
- Ask about the SYN480R circuit
- TI C6748 chip PRU part assembly software package sprc940.zip