wdt_enable() timeout method doesn't cause a reset

Go To Last Post
3 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I use the common watchdog timeout approach to perform a software reset of the 328P chip. I've received some reports from my users that this doesn't always have the desired effect and the board just hangs, requiring a power cycle.

#include <avr/wdt.h>
wdt_disable();
wdt_enable(WDTO_15MS);
while (1) {}

Any thoughts on why this might not always work ?

 

The use-case is part of a routine to set the board back to factory defaults - hold the pushbutton switch at power-on, release and hold for another 5 secs to avoid accidents, wait for the LED to flash, release the switch, write default values to EEPROM and then reset the processor. The values are written as expected, so it must be the final reset that is failing.

 

Clearly, I have no control over the user's Arduino IDE configuration or what dodgy hardware they may be using.

 

I could use the other approach, which would (for this specific purpose) have the same result:

asm volatile ("jmp 0"); 

or

void (*reboot_fptr)(void) = 0;
// ...
reboot_fptr();

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Does the code (Arduino library?) have *any* WDR opcodes in it?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

clawson wrote:

Does the code (Arduino library?) have *any* WDR opcodes in it?

 

It's from avr-libc, so not specifically part of the Arduino software.

 

A quick search says no, other than in the bootloader: https://github.com/arduino/Ardui...

 

avr-libc source: https://www.nongnu.org/avr-libc/...

 

I posted this in the Arduino forum as I don't have the ability to meddle with fuses, toolchain, etc.