I'm sorry guys, I disturb you here with avr. I hope you have a good mood before winter holidays and I wish to all of you and your families be happy and healthy. let's don't forget as this is a magic time for our kids. My best wishes from Ukraine!
Ok. Here is my problem.
I can't wake up Tiny13 from "Power-down" sleep mode, but it awake if set "Idle Mode". I checking current consumption with my multimeter, Tiny13 goes to sleep successfully - only 0,5 microA. If sleep mode disable it takes 1,2mA.
According to datasheet (table 7-1 on page 30) it should awake from INT0 interrupt source, which I need.
What am I doing wrong? Should I enable watchdog? (but I don't need to wake-up from it.) Thank you.
#define F_CPU 1200000UL #include <avr/io.h> #include <util/delay.h> #include <avr/interrupt.h> #include <avr/sleep.h> #define LED_ON PORTB |= (1 << PB0) #define LED_OFF PORTB &=~(1 << PB0) #define LED_TOG PORTB ^= (1 << PB0) #define BACKLIGHT 5000 void setup () { // *** Port Setup *** // PB1 - Button // 0 input // PB0 - LED // 1 output DDRB = (0 << PB5) | (0 << PB4) | (0 << PB3) | (0 << PB2) | (0 << PB1) | (1 << PB0); PORTB = (1 << PB5) | (1 << PB4) | (1 << PB3) | (1 << PB2) | (1 << PB1) | (0 << PB0); // Analog Comparator Disable ACSR |= (1 << ACD); // *** Interrupts Setup *** // Enable External Interrupt on INT0 GIMSK |= (1 << INT0); // The falling edge will generate an interrupt (H to L) MCUCR |= (1 << ISC01); // Enable Sleep Mode: Power-down set_sleep_mode(SLEEP_MODE_PWR_DOWN); } ISR (INT0_vect) { asm("nop"); } void go_to_sleep_mode () { //MCUCR |= (1 << SM1); //MCUCR |= (1 << SE); //asm("sleep"); sleep_enable(); sleep_cpu(); } int main(void) { setup(); sei(); while(1) { // Please sleep now go_to_sleep_mode(); cli(); LED_ON; _delay_ms(BACKLIGHT); LED_OFF; _delay_ms(BACKLIGHT); sei(); } }