Hi, I'm a beginner in programming Nordic uC and I would like to know how to enable the watchdog in my application. Are there particular functions to call? Thanks!
Hi, I'm a beginner in programming Nordic uC and I would like to know how to enable the watchdog in my application. Are there particular functions to call? Thanks!
Hi,
This is how i do it
Init
static void System_task_initWatchdog(void)
{
nrf_drv_wdt_config_t config = NRF_DRV_WDT_DEAFULT_CONFIG;
uint32_t err_code = nrf_drv_wdt_init(&config,WatchdogHadler);
APP_ERROR_CHECK(err_code);
err_code = nrf_drv_wdt_channel_alloc(&m_channel_id);
APP_ERROR_CHECK(err_code);
nrf_drv_wdt_enable();
}
Feed
nrf_drv_wdt_channel_feed(m_channel_id);
sdk_config.h
#ifndef WDT_ENABLED
#if WDOG
#define WDT_ENABLED 1
#else
#define WDT_ENABLED 0
#endif
#endif
#if WDT_ENABLED
// <o> WDT_CONFIG_BEHAVIOUR - WDT behavior in CPU SLEEP or HALT mode
// <1=> Run in SLEEP, Pause in HALT
// <8=> Pause in SLEEP, Run in HALT
// <9=> Run in SLEEP and HALT
// <0=> Pause in SLEEP and HALT
#ifndef WDT_CONFIG_BEHAVIOUR
#define WDT_CONFIG_BEHAVIOUR 0
#endif
// <o> WDT_CONFIG_RELOAD_VALUE - Reload value <15-4294967295>
#ifndef WDT_CONFIG_RELOAD_VALUE
#define WDT_CONFIG_RELOAD_VALUE 20000
#endif
// <o> WDT_CONFIG_IRQ_PRIORITY - Interrupt priority
// <i> Priorities 0,2 (nRF51) and 0,1,4,5 (nRF52) are reserved for SoftDevice
// <0=> 0 (highest)
// <1=> 1
// <2=> 2
// <3=> 3
// <4=> 4
// <5=> 5
// <6=> 6
// <7=> 7
#ifndef WDT_CONFIG_IRQ_PRIORITY
#define WDT_CONFIG_IRQ_PRIORITY 7
#endif
Also since it is not a protected service you can write directly to the registers if you want:
void wdt_init(void)
{
NRF_WDT->CONFIG = (WDT_CONFIG_HALT_Pause << WDT_CONFIG_HALT_Pos) | ( WDT_CONFIG_SLEEP_Run << WDT_CONFIG_SLEEP_Pos);
NRF_WDT->CRV = 150*32768; // 150 sec. timout
NRF_WDT->RREN |= WDT_RREN_RR0_Msk; //Enable reload register 0
NRF_WDT->TASKS_START = 1;
}
//And this bit refreshes the WDT. Just put it where ever you think is appropriate.
NRF_WDT->RR[0] = WDT_RR_RR_Reload; //Reload watchdog register 0
Hi, thanks for your answer! I'm not sure what nrf_drv_wdt_channel_feed(m_channel_id); is useful for and where to place it (maybe in the for(;;)?). Moreover what's the meaning of WDT_CONFIG_RELOAD_VALUE? Thanks!
feed can be placed in the main loop WDT_CONFIG_RELOAD_VALUE is a time in milliseconds before the WD is accrues. every feed you reload the timer aggain