ATTiny 85 Sleep

Hi,

I have been playing round with the watch dog timer and sleep functions on an ATTiny85 from Digistump and no surprises it gets to sleep and never comes back again. The idea is to flash two LEDs quickly once a second, sleeping most of the time until woken by the WDT. The attachment shows the trimmed down code in its simplest form. Which flashes the LEDs once and never comes out of sleep.

I have read through a number of the examples on the forum and the avr-libc, still scratching my head.

Help greatly appreciated.

Steve.

//Includes

#include <avr/wdt.h>
#include <avr/sleep.h>
#include <avr/power.h>

//defintions

#define ledOne 3 // on 85
#define ledTwo 1 // on 85

void setup() {

wdt_enable(WDTO_1S); //Set for 1 second

pinMode (ledOne, OUTPUT);
pinMode (ledTwo, OUTPUT);

}

void loop() {

wdt_reset(); //reset the dog.
blink_led(); // blink the leds.
system_sleep(); //go to sleep

}

// system wakes up when watchdog is timed out
void system_sleep() {
  set_sleep_mode(SLEEP_MODE_PWR_DOWN); // sleep mode is power down
  sleep_enable(); // ready to sleep
  sleep_mode(); // system sleeps
  sleep_disable(); // Back after wdt bite
}

void blink_led(){

digitalWrite (ledOne, HIGH);// flash led one
delay (50);
digitalWrite (ledOne, LOW);
delay (50);

digitalWrite (ledTwo, HIGH);//flash led two
delay (50);
digitalWrite (ledTwo, LOW);
delay (50);
  
}

_85_Sleep_Mode.ino (840 Bytes)

Have you found a solution to your problem?