I am working with ATtiny85. I want to put my MCU in IDLE Sleep mode and after every five minutes, I want to write data into EEPROM. I am using Timer 0 overflow interrupt to count 5 mins. Counting will be done in ISR. I have a query here

  1. Does CPU come out of IDLE Sleep mode when timmer overflow interrupt is generated? In the datasheet, they didn't give Timmer Overflow interrupt as a wake-up source.
void setup() {
  set_eeprom_default(); // Initialize the EEPROM with default values
  configure_idle_mode(); // Configure idle sleep mode bits
  timer_setup(); // Initialize timer and start timer
  EEPROM.get(Address, timer_count); // Get the value of timer counter

void loop() {
  if (timer_count < max_timer_count) {
    enable_sleep(); // Enable Sleep mode. MCU goes to sleep here

  if (is_five_min == 1) { // Update EEPROM value after every 5 min
    is_five_min = 0; // Reset the flag
  • 4
    \$\begingroup\$ are you using an attiny85 or esp32? \$\endgroup\$
    – dandavis
    Aug 21, 2021 at 4:45
  • \$\begingroup\$ I am using ATtiny85 \$\endgroup\$
    – sri
    Aug 23, 2021 at 5:20

1 Answer 1


Yes, TIMER0 overflow is a wakeup from sleep. Relevant text in Section 7.1.1: "Idle mode enables the MCU to wake up from external triggered interrupts as well as internal ones like the Timer Overflow". Also see Table 9-1 (Reset and Interrupt Vectors). It sounds like you've already declared the TMR0_OVF_vect ISR.

Additionally, enable_sleep does not put the AVR into the sleep mode, it only sets the SE bit in the MCUCR register. You have to call sleep_cpu() afterwards to actually put the microcontroller to sleep. Typically, the sequence would be:

sleep_enable();  // Set SE bit
sei();           // Enable interrupts
sleep_cpu();     // Go to sleep
sleep_disable(); // Clear SE bit

See the description of this in the avr-libc documentation.

  • \$\begingroup\$ Thank you awjlogan \$\endgroup\$
    – sri
    Aug 23, 2021 at 5:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.