Arduino Pro Mini and Watch Dog Timer Problem

Hi All,

I’m having a real hard time digging up information on this. My objective is to simply run the Watch Dog Timer (WDT) for the full 8 seconds on my arduino pro mini.

It runs perfectly when configured for 2 seconds or for 1 second. However, if I try to set the timeout to 4 or 8 seconds, the onboard LED 13 flashes rapidly and does not work. I’ve included the source below. I can’t imagine what I’m doing wrong.

Thanks for any help,

Jeremy

#include <avr/interrupt.h>;
#include <avr/wdt.h>;

/*
 * The setup function.
 */
void setup() {
  Serial.begin(57600);
  wdtSetup();
}

ISR(WDT_vect)
{
    Serial.println("Watchdog!");
}

/*
 * The main loop.
 */
void loop()
{

}

/*
 * Setup of the watchdog timer.
 */
void wdtSetup() {
  cli();
  MCUSR = 0;
  WDTCSR |= B00011000;
  WDTCSR = B01000111; // 2 second bitstring, works fine
  WDTCSR = B01001000; // 4 second bitstring, no dice
  WDTCSR = B01001001; // 8 second bitstring, no dice
  sei();
}

I have heard that you need to change to the Optiboot bootloader to use the watchdog successfully. If you have a 16MHz Pro Mini, that would effectively make it a small Uno. Burn the bootloader with an AVR programmer or another Arduino as ISP.

If you have an 8MHz Pro Mini, you can still use the Uno bootloader, but you will need to upload to it at half speed, so continue to use the Pro Mini board selection in the IDE when uploading to it.

You can also choose to not use a bootloader at all, and upload your sketch to the board using an AVR programmer or another Arduino as ISP. The IDE has the menu selection Upload Using Programmer for that purpose. That would keep the bootloader from "getting in the way" of your watchdog reset.

Others on the forum may be able to chime in with more technical info.

That is very informative. Thank you very much.

Here's the issue report for this bug:

I definitely recommend using the Uno bootloader for 16MHz Pro Mini, just remember to always use it as an Uno after installing that bootloader. Not only does that fix the watchdog reset loop bug but it also frees up 1.5kB of flash memory!

For 8MHz I'd recommend to use GitHub - MCUdude/MiniCore: Arduino hardware package for ATmega8, ATmega48, ATmega88, ATmega168, ATmega328 and ATmega328PB, which includes the optiboot bootloader.

Upload Using Programmer is good too but I usually am using Serial debug output while developing so it's more convenient to use the bootloader and then maybe Upload Using Programmer for the finished product when the bootloader is not really helpful to me anymore.

pert:
Here's the issue report for this bug:
ProMini: Reboot loop when using watchdog · Issue #150 · arduino/ArduinoCore-avr · GitHub
I definitely recommend using the Uno bootloader for 16MHz Pro Mini, just remember to always use it as an Uno after installing that bootloader. Not only does that fix the watchdog reset loop bug but it also frees up 1.5kB of flash memory!

You are my Hero!!! :smiley: :smiley:

To contribute some infos about burning bootlader, with arduino as ISP, I personaly faced a problem with the upload speed. I was getting the error "avrdude stk500_getsync(): attempt 1..10 out of 10 not in sync resp=0xff."
I changed the upload speed from the boards.txt file to "uno.upload.speed=19200", like the default value that was given in the example ArduinoISP.

This is simply additional info on this issue:

The code below executes as expected as long as the WDT is not activated. When the delay statement is increased to 3000 the Pro Mini blinks the LED at a 10 Hz rate with ~15% duty cycle. Uploading is not possible even holding down the reset switch (no surprise).

Recovery can be effected only after removing power and uploading again.

#include <avr/wdt.h>

void setup() {
Serial.begin(9600);
Serial.println(“start”);
wdt_enable(WDTO_2S);
}

void loop() {
delay(1000);
digitalWrite(LED_BUILTIN,!digitalRead(LED_BUILTIN)); // blink LED
wdt_reset();
}

Did you ceck with newer verson of arduino. what version you are using. there is some buggs on older version.

munib chauhan
Embatronix(https://www.embatronix.com)

I'm using an UNO as ISP, loaded "Arduino as ISP" sketch on UNO, then selecting Minicore's 3.3V 8MHz board and other settings before selecting "Burn bootloader."

Connections: Uno 10 to pro-mini reset, Uno 11, 12, 13 to pro-mini 11, 12, 13 (10 to 13 all through a low level converter.) I'm assuming wiring is ok because I'm able to burn bootloader using Nick Gammon's programmer sketch with same connections.

But when trying to burn Minicore's bootloader to a 3.3v 8MHz pro-mini I get the following errors:
Can anyone point me in the right direction? My aim is to get WDT working on this unit.

Arduino: 1.8.9 (Mac OS X), Board: "ATmega328, Yes (UART0), 328P / 328PA, BOD 2.7V, LTO enabled, 8 MHz external"

/Users/heinmyburgh/Library/Arduino15/packages/arduino/tools/avrdude/6.3.0-arduino14/bin/avrdude -C/Users/heinmyburgh/Library/Arduino15/packages/MiniCore/hardware/avr/2.0.3/avrdude.conf -v -patmega328p -carduino -P/dev/cu.wchusbserial1420 -b19200 -e -Ulock:w:0x3f:m -Uefuse:w:0b11111101:m -Uhfuse:w:0xd6:m -Ulfuse:w:0b11110111:m

avrdude: Version 6.3-20171130
Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/
Copyright (c) 2007-2014 Joerg Wunsch

System wide configuration file is "/Users/heinmyburgh/Library/Arduino15/packages/MiniCore/hardware/avr/2.0.3/avrdude.conf"
User configuration file is "/Users/heinmyburgh/.avrduderc"
User configuration file does not exist or is not a regular file, skipping

Using Port : /dev/cu.wchusbserial1420
Using Programmer : arduino
Overriding Baud Rate : 19200
AVR Part : ATmega328P
Chip Erase delay : 9000 us
PAGEL : PD7
BS2 : PC2
RESET disposition : dedicated
RETRY pulse : SCK
serial program mode : yes
parallel program mode : yes
Timeout : 200
StabDelay : 100
CmdexeDelay : 25
SyncLoops : 32
ByteDelay : 0
PollIndex : 3
PollValue : 0x53
Memory Detail :

Block Poll Page Polled
Memory Type Mode Delay Size Indx Paged Size Size #Pages MinW MaxW ReadBack


eeprom 65 20 4 0 no 1024 4 0 3600 3600 0xff 0xff
flash 65 6 128 0 yes 32768 128 256 4500 4500 0xff 0xff
lfuse 0 0 0 0 no 1 0 0 4500 4500 0x00 0x00
hfuse 0 0 0 0 no 1 0 0 4500 4500 0x00 0x00
efuse 0 0 0 0 no 1 0 0 4500 4500 0x00 0x00
lock 0 0 0 0 no 1 0 0 4500 4500 0x00 0x00
calibration 0 0 0 0 no 1 0 0 0 0 0x00 0x00
signature 0 0 0 0 no 3 0 0 0 0 0x00 0x00

Programmer Type : Arduino
Description : Arduino

avrdude: stk500_getparm(): (a) protocol error, expect=0x14, resp=0x14

avrdude: stk500_getparm(): (a) protocol error, expect=0x14, resp=0x02

avrdude: stk500_getparm(): (a) protocol error, expect=0x14, resp=0x10
Hardware Version: 425479
Firmware Version: 25192964.-1441849512
Topcard : STK502
Vtarget : 1.8 V
Varef : 0.0 V
Oscillator : Off
SCK period : 0.1 us

avrdude: stk500_initialize(): (b) protocol error, expect=0x10, resp=0x01
avrdude: initialization failed, rc=-1
Double check connections and try again, or use -F to override
this check.

avrdude: stk500_disable(): protocol error, expect=0x14, resp=0x10

avrdude done. Thank you.

Error while burning bootloader.