Is there an app-note, tutorial, or example of how to use the watchdog timer to reset the MCU if the application hangs?
Is there an app-note, tutorial, or example of how to use the watchdog timer to reset the MCU if the application hangs?
Hi Ole,
I tried the code below, but it doesn't work. It does not go to the handler, and it doesn't reset either. I closed the debugger and did a power cycle as required. In the handler, all I do is turn the LED on (LED function works with a button press, for example). I'm not reloading it anywhere yet either. What am I doing wrong?
void watchdog_init(void) { NRF_WDT->CONFIG = (WDT_CONFIG_HALT_Pause << WDT_CONFIG_HALT_Pos) | (WDT_CONFIG_SLEEP_Pause << WDT_CONFIG_SLEEP_Pos);
NRF_WDT->CRV = (32768 * 1); // Timeout period of 1 s
NRF_WDT->RREN |= WDT_RREN_RR0_Msk; //Enable reload register 0
NRF_WDT->INTENSET = WDT_INTENSET_TIMEOUT_Msk;
NVIC_ClearPendingIRQ(WDT_IRQn); NVIC_SetPriority(WDT_IRQn, APP_IRQ_PRIORITY_HIGH); NVIC_EnableIRQ(WDT_IRQn);
NRF_WDT->TASKS_START = 1; // Watchdog start }
Thank you!
Gil
Hi Ole,
I tried the code below, but it doesn't work. It does not go to the handler, and it doesn't reset either. I closed the debugger and did a power cycle as required. In the handler, all I do is turn the LED on (LED function works with a button press, for example). I'm not reloading it anywhere yet either. What am I doing wrong?
void watchdog_init(void) { NRF_WDT->CONFIG = (WDT_CONFIG_HALT_Pause << WDT_CONFIG_HALT_Pos) | (WDT_CONFIG_SLEEP_Pause << WDT_CONFIG_SLEEP_Pos);
NRF_WDT->CRV = (32768 * 1); // Timeout period of 1 s
NRF_WDT->RREN |= WDT_RREN_RR0_Msk; //Enable reload register 0
NRF_WDT->INTENSET = WDT_INTENSET_TIMEOUT_Msk;
NVIC_ClearPendingIRQ(WDT_IRQn); NVIC_SetPriority(WDT_IRQn, APP_IRQ_PRIORITY_HIGH); NVIC_EnableIRQ(WDT_IRQn);
NRF_WDT->TASKS_START = 1; // Watchdog start }
Thank you!
Gil
Hi,
If you are using the soft device, you cannot set the priority level as high which is reserved in this case. Try to set it to low priority.
Thank you Sébastien, Unfortunately it still does not work. I tried it with this: NVIC_SetPriority(WDT_IRQn, APP_IRQ_PRIORITY_LOW); Regards, Gil
Thank you Sébastien, Unfortunately it still does not work. I tried it with this: NVIC_SetPriority(WDT_IRQn, APP_IRQ_PRIORITY_LOW); Regards, Gil
An update: It now resets. I'm going into sleep mode, so I had to change WDT_CONFIG_SLEEP_Pause to WDT_CONFIG_SLEEP_Run.
But it still does not go to the WDT_IRQHandler() ISR. So I'm guessing the problem is in the INTENSET and NVIC instructions.
An update: It now resets. I'm going into sleep mode, so I had to change WDT_CONFIG_SLEEP_Pause to WDT_CONFIG_SLEEP_Run.
But it still does not go to the WDT_IRQHandler() ISR. So I'm guessing the problem is in the INTENSET and NVIC instructions.