NRF52 watchdog problem (myBoardNRF5)

  • Have I missed something or is there an issue with watchdog on NRF52 - watchdog does not get suspended when sleeping ?

    Using mysensors 2.3.1 and NRF52832 (Ebyte module) with myboardNRF5. I finally took the time to simplify the code and seems you only need minimum sketch to replicate this, just sleep for longer than wdg period.

    Disabling it manually (wdg_disable) before entering sleep does not change this. I did read the disable is not working, but should set it for long period. Now testing with 20s sleep and 10s wdg period, reboots at every sleep after 10s.

    Ignore the TEST_PIN stuff, it's there to make it easier to re-program (STlink can't connect while sleeping).
    wait() seems to be calling wdg_reset since it doesn't boot there.

    #define MY_DEBUG
    #define MY_RADIO_NRF5_ESB
    #include <MySensors.h>
    #ifdef MY_DEBUG
    #define DBG_PRINT(...)    Serial.print(__VA_ARGS__)
    #define DBG_PRINTLN(...)    Serial.println(__VA_ARGS__)
    #define DBG_PRINT(...)    do {} while (0)
    #define DBG_PRINTLN(...)    do {} while (0)
    #define REED_PIN	18
    #define TEST_PIN	29	// sleep -> wait
    void setup()
    	DBG_PRINT("PART: ");
    void loop()
    	int8_t stat=0;
    	if (digitalRead(TEST_PIN)) {
    		//int8_t stat = smartSleep(digitalPinToInterrupt(REED_PIN), FALLING, 20000);
    		//int8_t stat = sleep(digitalPinToInterrupt(REED_PIN), FALLING, 20000);
    		int8_t stat = sleep(20000);
    	else {
    	DBG_PRINT("Wakeup, stat ");

  • Mod

    @kisse66 I know @petewill is experimenting with Nrf52 and watchdogs; maybe he has some more info on the topic.

  • @kisse66 no, once watchdog is started it can't be disabled, until hard reset. It is deliberate design choice for some reason.

  • @monte understood, however the MySensorsNRF5 says

    "*The MySensors port for nRF5 supports using the Watchdog. You can use the same commands like defined in "avr/wdt.h" but disable cannot disable the watchdog. The watchdog is set to a period of 36h of CPU runtime.

    When the CPU is in a sleep mode, the watchdog timer is stopped*."

    Especially the suspend, or better lack of, under sleep is my problem. I could set it for >20 minutes (sleep time) perhaps, but if the CPU hangs the long period will use a lot of battery before recovering.

  • @kisse66 Mysensors can't alter the way the function is implemented in nrf chip. If you go to a link I've posted above, you will see that it is confirmed behavior that is expected by Nordic. Once you have set up and enabled watchdog on NRF5 chip it can't be disabled, nor changed to other settings, without reset via one o these: power, pin, brownout or watchdog.
    I guess the description you are referring to is simply wrong, which is confirmed by your experience. I think we need to ask someone capable to edit this part of the description. Can you specify, where exactly this quote is taken from?

  • Mod

    @monte the quote is probably from (section "Watchdog timer" near the end of the page)

  • yep.

    So if the description is wrong you can't really use WDG with sleeping sensors, unless the sleep period is less than WDG period ?

  • @kisse66 try setting longest time period for watchdog and little less for sleep. Every wake up feed watchdog and if nothing happened sleep again. I guess it won't eat to much power, and you can keep your watchdog running.

  • @monte yes, makes sense. I know it takes quite a lot of energy to do one cycle due to multiple (slow) sensors and sending those, but have not really looked into a short wake, skip everything and back to sleep. Could easily count wakeups and only do the sensors every Nth wakeup. Maybe it's actually a good way.
    I have some weird issues for which I need the WDG. Found and fixed one forever loop in I2C, but it did not fix all. Can't pinpoint the issue and now it drains the battery randomly by getting stuck somewhere after a week or a few months.

    Now I remember one experiment over a year ago with NRF51 based small board I used as mysensors remote. It has just one push button. This silicon version had problem with high current draw if waiting for pin change, so I just made it wakeup every 750ms, poll the button and if not pressed go back to sleep. CR2032 lasted way over a year. Had already forgotten that, good that you reminded!

  • Mod

    The atmega328 implementation of MySensors sleep wakes up every 8 seconds and result in many years of battery life, so waking up on the nrf5 shouldn’t be much of a problem I think.

Log in to reply

Suggested Topics

  • 3
  • 2
  • 3
  • 2
  • 15
  • 2