Resetting / Rebooting ATTiny85 with Watchdog Timer (WDT)

I was expecting this to be a no-brainer. I use WDT on Arduinos w/o any trouble. The code for Arduino would roughly be:

#include <arv/wdt.h>

while (true) {}

After one second, the arduino reboots because of the WDT.

That does not work for the ATTiny85. It wants to call the WDT_vect ISR instead and somehow (at least for me) hangs up such that I have to remove power from the ATTiny85 to get it running again.

After hours of banging my head against the wall and searching every source repeatedly I finally was able to put together the following code which correctly reboots the ATTiny85:

#include <avr/wdt.h>

void reboot(
    ) {

WDTCR = 0xD8 | WDTO_1S;

while (true) {}

} //reboot

void setup (
    ) {



In this example, the WDIE bit is set to 1 which is necessary to get the MCU to reset. Evidently wdt_enable() is not doing that for the ATTiny85. The other possibility is that the wdt_enable() procedure is not fast enough as the ATTiny85 requires everything be set properly in 4 clock cycles.

Note: You MUST include wdt_disable() as the first instruction in setup(). I tried going without this and it hangs under that condition as well.

Either way, this code is working for me, so after 2 evenings of frustration, I can proceed with my project!

This entry was posted in c-tinys and tagged . Bookmark the permalink.

One Response to Resetting / Rebooting ATTiny85 with Watchdog Timer (WDT)

  1. mahesh says:

    hi, your code didn’t work for my ATtiny85 (programmed using an Arduino Uno as ISP) but the following did. the main difference is that MCUSR &= ~(1<<WDRF) needs to be set before wdt_disable() in your setup code, so it's the first thing that's executed.

    void setup() {
    MCUSR &= ~(1<<WDRF); // reset status flag
    //… other stuff

    void loop() {
    if (some-condition) reboot2();

    void reboot2() {

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s