This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

nRF52840 watchdog for Arduino Nano 33 BLE Sense

Writing an app for the Arduino Nano 33 BLE Sense:

https://store.arduino.cc/usa/nano-33-ble-sense

Basically I am reading all sensors on the Sense board (temperature, humidity, pressure, acceleration, gyro, light, noise), sending the data to a Raspberry Pi for processing, and then to Graphite for long term storage, and visualization with Grafana. This is the project page:

https://github.com/FlorinAndrei/WeatherStation

So far so good and the project works pretty well. But there's one snag:

Every few days the Arduino sketch stops working - it just hangs. I will attempt to troubleshoot it and figure out what causes the hang - there are several libraries I'm using for the various sensors, and perhaps there's a bad interaction somewhere. Or some memory leak, I'm not sure.

Anyway, meanwhile, if I had a way to trigger a watchdog to reset the board, that would be an acceptable workaround.

Is there a library I could integrate with the Arduino IDE that would give me a watchdog for this CPU? And is that documented somewhere, with examples?

Thanks!

  • It works! Thank you.

    int ledState = LOW;
    
    void setup() {
      Serial.begin(115200);
      pinMode(LED_BUILTIN, OUTPUT);
    
      //Configure WDT.
      NRF_WDT->CONFIG         = 0x01;     // Configure WDT to run when CPU is asleep
      NRF_WDT->CRV            = 32769;    // CRV = timeout * 32768 + 1
      NRF_WDT->RREN           = 0x01;     // Enable the RR[0] reload register
      NRF_WDT->TASKS_START    = 1;        // Start WDT       
      
      Serial.println("booting up");
    }
    
    void loop() {
      // Reload the WDTs RR[0] reload register
      NRF_WDT->RR[0] = WDT_RR_RR_Reload;
    
      ledState = ledState ? LOW: HIGH;
      digitalWrite(LED_BUILTIN,  ledState);
    
      delay(2000);
    }

    But there's a catch: the watchdog keeps working even when you try to upload another sketch. If the watchdog timeout is too low (1 second in my case), the Nano 33 will reboot when you try to upload the sketch.

    The solution: tap the Reset button two times quickly. The LED will start pulsing slowly. Now you can upload your sketch on the alternative COM port.

    I've a question: I believe it is possible to program a timeout shorter than 1 second into the watchdog, but is it recommendable? I mean, will there be any issues with short watchdog times? (assuming such a time makes sense for your sketch)

  • Florin Andrei said:
    It works! Thank you.

    Great! 

    Florin Andrei said:
    I've a question: I believe it is possible to program a timeout shorter than 1 second into the watchdog, but is it recommendable? I mean, will there be any issues with short watchdog times? (assuming such a time makes sense for your sketch)

     I think that a watchdog timer with a sub 1 second timeout will do more harm than good. If you have full control of what the nRF52840 is doing, then one could do it, but there may occur BLE events and other interrupts that may prevent the RR register from being reloaded in time. Hence, I would not recommend it. 

     Best regards

    Bjørn

  • Hi there,

    I am not trying to hijack this thread but I am also very interested in the Nano 33 BLE and was wondering if this watchdog setup could be used to wake the NRF from

    NRF_POWER->SYSTEMOFF = 1;
    . My initial tests to do so have failed.

  • No, the Watchdog does not run in System OFF, see Reset behavior and footnote 6

    6 Watchdog reset is not available in System OFF.

Related