Hello everybody,

I'm playing around with the watchdog and "misuse" it as a software reset. I can send a command (via serial) to my arduino that performs such a soft-reset. but after this it keeps resetting (L blinks fast). even with a wdt_disable() in the setup-routine. What am I doing wrong? How can i cope with this?

Thanks a lot!

regards, Eckard

It sounds like the watchdog is firing before you get to the disable command in your setup.

This can happen if you set the watchdog timer to be too short. The only way out of this I know is to reprogram in the boot loader, it needs a separate programmer to do this.

I was able to reprogram my way out of a similar situation by initiating an upload (of a sketch NOT containing watchdog code) via power-on instead of reset-button... (reset button does not turn off the watchdog, power cycle does...) Whether this works depends on whether you have one of the "sneaky" bootloaders that does "fast application boot on powerup."

I was able to resurrect my Arduino (see other thread). But my question was another one, so I think I have to rephrase my question:

I wrote code, that enables me to send commands via serial-port to my arduino. there are commands like "digitalWrite" to control pins remotely and there is one "reset", that calls the watchdog to reset the arduino remotely (so it is not called in the setup() routine). it does nothing more than:

} while(0)

But this does not work as I suspected. It does not reset the arduino like after connecting it. It makes the arduino flash L continously. Only dis- and reconnecting the arduino to the USB makes it work again.

Changing WDTO_15MS to other values does not change the effect. it only delays it.

Can anybody explain what's going wrong here and how to fix it?

Thank you very much! Eckard

The problem is that a RESET does not turn off the watchdog timer once it has been turned on, and neither does the bootloader. So you set things up to have the watchdog cause a reset in 15ms, and the reset occurs. Now the bootloader starts up, and starts its LED-flashing, and OOPS another 15ms has gone by with no one feeding the watchdog, and it resets again. This repeats until a power cycle turns off the watchdog. (This behavior is explicitly described in the ATmega datasheet...)

I understand.

But is there no way, to turn it off again? wdt_disable() in the setup() routine does not have any effect.

Thank you very much for your help!

It never gets to the setup() function because the watchdog happens before the bootloader starts the sketch.

If you power cycle the device while starting the "upload", you MIGHT be able to catch the first bootloader cycle before the watchdog is turned on the first time by your sketch. But some bootloaders have a feature that runs the sketch immediately after poweron (and only goes to the bootloader on reset), and in any case the timing is pretty critical.

Ok. Too bad...

Nevertheless, thank you very much for your help!

You can of course fix this by using one of the "burn bootloader" techniques to completely erase and re-program the AVR. There are some techniques that don't even require additional hardware other than some wires.