Important changes to forums and questions
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
9 years, 9 months ago.
Watchdog and Sleep mode on nrf51 DK
Hi everybody,
I want to know if it there is a code example for watchdog & sleep mode on the nrf51 board without use the ble.waitforevent() function and the ticker.
I want use watchdog timer and sleep mode function int the nrf51.h header instead ticker&waitforevent()...because i want a power consumtption optimized code.
Thank you for your help and sorry for my english. Yacire.
Question relating to:
1 Answer
9 years, 9 months ago.
Hi,
using Watchdog is pretty simple. Here's some code I wrote:
#ifndef _H_WATCHDOGTIMER_H #define _H_WATCHDOGTIMER_H namespace WatchDogTimer { void init(float seconds = 6.0) { NRF_WDT->CONFIG = (WDT_CONFIG_SLEEP_Run << WDT_CONFIG_SLEEP_Pos); NRF_WDT->CRV = seconds * 32768; // 32k tick NRF_WDT->RREN = WDT_RREN_RR0_Enabled << WDT_RREN_RR0_Pos; NRF_WDT->TASKS_START = 1; } void kick() { NRF_WDT->RR[0] = WDT_RR_RR_Reload; } }; #endif//_H_WATCHDOGTIMER_H
Just call WatchDogTimer::init() at the beginning of your program, then WatchDogTimer::kick() periodically, before the 6 seconds runs out. You can change the watch dog time when calling the init() function.
Of course you have to use a Ticker to kick the dog, OR if you have some other periodic task you can kick during that.
Thank you Prashant,
But i don't understand, if i use watchdog timer, i don't need to use the ticker, no ?? Maybe i can use a flag for reload the watchdog ?
I don't understand why 6 second are the maximum in the function init() ? i read 4 seconds is the max for the watchdog, after the MCU reset ...
Thank you very much for your help, Yacire.
posted by 13 Feb 2015Hi,
the purpose of the watchdog is to reset the mcu after x second of no "response" (which means the mcu crashed). You have to periodically reset the watchdog to indicate that the mcu is still running. So you'll need a timer or another event (e.g. every time a value is written over bluetooth) which will reset the watchdog.
6 seconds is just a random time out I chose, you can use any other timeout too. I don't know about the 4 sec maximum.. maybe I missed it in the data sheet. You can always set a shorter timeout like 1 or 2 sec.
posted by 13 Feb 2015