2

For the arduino Nano 33 BLE Sense board, the standard avr/wdt.h is not available. And it seems that no standard library provides it. How to use the watchdog system for this board ? I found no full information about it.

I've found the page https://www.mysensors.org/apidocs/group__avr__watchdog.html which allow to configure the reboot mode. And it works. But no way to configure the interruption mode with ISR() function. Moreover, there's no explanation about the manipulation of used register/variables for any fine configuration.

Simple code example with regular asynchronous stuff using the watchdog ISR() mechanism. It which works well with ATmega328 (e.g.UNO). But I do not find equivalent configuration for the Nano 33 BLE using the nRF52840.

# include <avr/wdt.h>

volatile byte led;
int k;

ISR(WDT_vect) {
  Serial.println("Asynchronous stuff in ISR() function");
  digitalWrite(LED_BUILTIN,led);
  led=!led;
}

void setup() {
  pinMode(LED_BUILTIN,OUTPUT);  
  led=0;
  
  Serial.begin(9600);
  while(!Serial) {}
  Serial.println("== R E B O O T ==");

  WDTCSR = ( 1 << WDE ) | ( 1 << WDCE );
  WDTCSR = ( 1 << WDP2 ) | ( 1 << WDP0 ) | ( 1 << WDIE ) ; // Interruption and timeout  1/2 s
}

void loop() {
  Serial.print("Loop #");
  Serial.println(k);
  if (k++%2) {
    Serial.println("Some stuff (even branch)");
    delay(1200);
  }
  else {
    Serial.println("Some stuff (odd branch)");
    delay(4800);
  }
}

Thks.

4
  • A little searching gave this link and that code seems to have worked: devzone.nordicsemi.com/f/nordic-q-a/53904/…
    – datenheim
    Commented Feb 10, 2023 at 7:41
  • Yes but your link provides the same information as I pointed out. It's only about the set of watchdog with simple reboot, not the set of ISR() mechanism at the end of the counting of the watchdog timer.
    – tjbtjbtjb
    Commented Feb 10, 2023 at 9:03
  • I've just added in a simple code example, working with a uno. Looking for equivalent code for the nano BLE.
    – tjbtjbtjb
    Commented Feb 10, 2023 at 9:06
  • You did see they used other defines than you? NRF_WDT->CONFIG = 0x01; and so on. I don't see that in your code. Your code in setup directly writes to MCU registers that do not exist on the nano 33 BLE. To configure it, you must take over those parts. If and how the watchdog interrupt can be intercepted on the nRF processor is another question. Typically the watchdog interrupt just does reset - normally it is intended not to happen within your firmware. If your idea is to time the execution of some code you might use a timer interrupt for this - not the watchdog.
    – datenheim
    Commented Feb 10, 2023 at 15:34

2 Answers 2

0

In fact, for the RF52940, I'm not sure that the watchdog can provide the needed interruption mechanism despite it exists the INTENSET bit for interruption according to the chipset doc https://content.arduino.cc/assets/Nano_BLE_MCU-nRF52840_PS_v1.1.pdf). But the good way is for sure the use of timers (and one can use more than just one, quite good).

For a similar behaviour as the code given for the UNO before, here is the code one can write for the Nano BLE using a timer interrupt (see https://github.com/khoih-prog/NRF52_MBED_TimerInterrupt for full and usefull doc).

#include "NRF52_MBED_TimerInterrupt.h"

volatile byte led;
volatile uint32_t count=0;
NRF52_MBED_Timer myTimer(NRF_TIMER_1); 
unsigned k=0;

void myHandler() {
  digitalWrite(LED_BUILTIN,led);
  led=!led;
  count++;
}

void setup() {
  pinMode(LED_BUILTIN,OUTPUT);  
  led=0;
  
  Serial.begin(9600);
  while(!Serial) {}
  Serial.println("== R E B O O T ==");

  if (myTimer.attachInterruptInterval(500*1000, myHandler)) // each 1/2 second
    Serial.println("myTimer launched");
  else
    Serial.println("Can not set the timer");
}

void loop() {
  Serial.print("Loop #");
  Serial.print(k);
  Serial.print(" and nb times in Handler : ");
  Serial.println(count);
  if (k++%2) {
    Serial.println("Some stuff (even branch)");
    delay(1200);
  }
  else {
    Serial.println("Some stuff (odd branch)");
    delay(4800);
  }
}
1
  • Re: "I'm not sure that the watchdog can provide the needed interruption mechanism despite it exists the INTENSET bit for interruption according to the chipset doc" To clarify: once the NRF52 watchdog ISR has fired you are on a one-way trip to a RESET in little more than about 60uS. It may not do what the OP needs. So if that's what you meant, yup, it's limited compared to what the AVR counterpart lets you do. For anyone that only needs 60uS before the impending reset, INTENSET usage should meet their requirements.
    – timemage
    Commented Feb 16, 2023 at 19:12
-1

You do not want to update your watchdog in an ISR. It is possible to get stuck but the ISR is continually triggered. I have seen this happen many times especially when a bad transient hits it. I normally use an external one so it will force a reset on the whole package. I do this by power cycling everything. Not all watchdog timers in processors will do an external reset.

2
  • I gave above an example working with UNO and I would like equivalent with the nano ble.
    – tjbtjbtjb
    Commented Feb 10, 2023 at 9:21
  • It works fine with UNO, Nano, and many others. I am not have a ble to try it.
    – Gil
    Commented Feb 10, 2023 at 18:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.