LPC1114 watchdog_interrupt

Publisher:温暖微笑Latest update time:2016-12-09 Source: eefocusKeywords:lpc1114 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

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:

Create a new watchdog routine

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:

  1. #include "lpc11xx.h"

  2. #include "wdt.h"

  3. #include "uart.h"

  1. void delay(void)

  2. {

  3.    uint16_t i,j;

  1.    for(i=0;i<5000;i++)

  2.    for(j=0;j<280;j++);

  3. }

  1. /******************************************/

  2. /* Function: Watchdog interrupt service function */

  3. /* Description: When the MOD value is set to 0x01, if it is not timely*/

  4. /* Feed the dog, and this interrupt function will be entered. */

  5. /******************************************/

  6. void WDT_IRQHandler(void)

  7. {

  8.    LPC_WDT->MOD &= ~(0x1<<2); // Clear the watchdog timeout flag WDTOF

  9.    // Below you can write what you want to do when the watchdog interrupt occurs

  10.    UART_send_byte('B');

  11.    delay(); //Wait for data to be sent

  12.    NVIC_SystemReset();

  13. }

  1. int main()

  2. {

  3.    UART_init(9600);

  4.    WDT_Enable(0); // Initialize the watchdog and feed it within 1 second

  5.    NVIC_EnableIRQ(WDT_IRQn);

  1.    while(1)

  2.    {

  3.       delay();

  4.       //WDTFeed();

  5.       UART_send_byte('A');

  6.    }

  7. }

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()

  1. #define SCB_AIRCR_VECTKEY_Pos 16

  2. #define SCB_AIRCR_SYSRESETREQ_Pos 2

  3. #define SCB_AIRCR_SYSRESETREQ_Msk (1UL << SCB_AIRCR_SYSRESETREQ_Pos)


  4. __STATIC_INLINE void NVIC_SystemReset(void)

  5. {

  6.    __DSB();

  7.    SCB->AIRCR = ((0x5FA << SCB_AIRCR_VECTKEY_Pos) | SCB_AIRCR_SYSRESETREQ_Msk);

  8.    __DSB();

  9.    while(1);

  10. }

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.

  1.    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.


Keywords:lpc1114 Reference address:LPC1114 watchdog_interrupt

Previous article:LPC1114 watchdog_window watchdog
Next article:LPC1114 watchdog_reset

Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号