Hello,
I'm trying to use the Watchdog timer on a Nano Every, but it seems not to trigger.
What am I missing?
void setup() {
wdt_disable();
Serial.begin(9600);
Serial.println("setup");
wdt_enable(WDTO_2S); // set watchdog to 2 secs
}
void loop() {
Serial.println("loop");
wdt_reset();
delay(3000); // should trigger watchdog after 2 secs
Serial.println("watchdog not triggered\n");
}
I haven't used the Every, but that's how I would expect it to work. Take a look at this and see if it helps: nanoEvery/nanoEvery.ino at main · mchlbrnhrd/nanoEvery · GitHub
Thank you, it's a nice example but is not working on my board.
Do I need some specific programming settings?
Guglie8:
What am I missing?
You are not using the correct syntax for the AT 4809 of the Nano Every.
from iom4809.h:
typedef enum WDT_PERIOD_enum
{
WDT_PERIOD_OFF_gc = (0x00<<0), / Off /
WDT_PERIOD_8CLK_gc = (0x01<<0), / 8 cycles (8ms) /
WDT_PERIOD_16CLK_gc = (0x02<<0), / 16 cycles (16ms) /
WDT_PERIOD_32CLK_gc = (0x03<<0), / 32 cycles (32ms) /
WDT_PERIOD_64CLK_gc = (0x04<<0), / 64 cycles (64ms) /
WDT_PERIOD_128CLK_gc = (0x05<<0), / 128 cycles (0.128s) /
WDT_PERIOD_256CLK_gc = (0x06<<0), / 256 cycles (0.256s) /
WDT_PERIOD_512CLK_gc = (0x07<<0), / 512 cycles (0.512s) /
WDT_PERIOD_1KCLK_gc = (0x08<<0), / 1K cycles (1.0s) /
WDT_PERIOD_2KCLK_gc = (0x09<<0), / 2K cycles (2.0s) /
WDT_PERIOD_4KCLK_gc = (0x0A<<0), / 4K cycles (4.1s) /
WDT_PERIOD_8KCLK_gc = (0x0B<<0), / 8K cycles (8.2s)
} WDT_PERIOD_t;
#include <avr/wdt.h>
void setup() {
//wdt_disable();
Serial.begin(9600);
Serial.println("setup");
wdt_enable(WDT_PERIOD_2KCLK_gc); // set watchdog to 2 secs
}
void loop() {
Serial.println("loop");
wdt_reset();
delay(3000); // should trigger watchdog after 2 secs
Serial.println("watchdog not triggered\n");
}
westfw
March 5, 2022, 1:00am
5
cattledog:
You are not using the correct syntax for the AT 4809 of the Nano Every.
from iom4809.h:
typedef enum WDT_PERIOD_enum
{
WDT_PERIOD_OFF_gc = (0x00<<0), / Off /
Sigh. It is unfortunate that avr/wdt.h defines the WDTO_2S
style timeouts unconditionally...
Thank you, that works!
Probably it can be explained in the wdt documentation.
By the way if I uncomment wdt_disable()
at the beginning of setup (seems a recommended practice) it doesn't work anymore.
#include <avr/wdt.h>
void setup() {
wdt_disable(); // this breaks the wdt_enable below
//delay(3); // unless with a delay here (at least 3ms on my board)
Serial.begin(9600);
Serial.println("setup");
wdt_enable(WDT_PERIOD_2KCLK_gc); // set watchdog to 2 secs
}
void loop() {
Serial.println("loop");
wdt_reset();
delay(3000); // should trigger watchdog after 2 secs
Serial.println("watchdog not triggered\n");
}
system
Closed
September 3, 2022, 9:17am
8
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.