[atmega8] Can't wake up from sleep mode

Do you have a question? Post it now! No Registration Necessary

Translate This Thread From English to

Hi.

I am working with Atmega8 and I installed Timer/Count2 interrupt
service routine. Following the Atmega8 manual, it is possilble that
Timer/Count2 ISR can wake up sleep mode(power save)if AS2 is set in
ASSR.

But, My code never wake up.

#include <avr/io.h>
#include <avr/interrupt.h>
#include <avr/signal.h>
#include <stdio.h>

void Uart_Put_Char(unsigned char data)
{
        while ( !( UCSRA & (1<<UDRE)) );
        UDR = data;
}

void Hardware_Init(void)
{
        // Set Sleep Mode
    MCUCR = 0xb0;
    UBRRL = 16;
    UCSRA = 0x00;
    UCSRB = 0x18;
    //Timer Interrupt Setting.
    // AS2 Set in ASSR because wake up from power save mode
    ASSR |= 0x08;
        // Clock(16Mhz) / 256
    TCCR2 = 0x06;
    // X / (249 + 1)
        // it means that Timer ISR called every 250hz.
    OCR2  = 249;
    // Timer/Counter2 Output Compare Match Interrupt Enable
    TIMSK = 0x80;
    // Timer/Counter Register Reset.
    TCNT2 = 0x00;

    __asm volatile("cli");
}

SIGNAL(SIG_OUTPUT_COMPARE2)
{
    Uart_Put_Char('C');
}

void SaveMode(void)
{
    while ( !( UCSRA & (1<<TXC)) );
    __asm volatile ("sleep");
}

void main(void)
{
        Hardware_Init();
    __asm volatile("sei");

        while(1)
        {
                Uart_Put_Char('A');
                SaveMode();
                Uart_Put_Char('B');
        }
}

This code's result is just "A" and the worst thing is that it never
print "C"
Could you tell me why ?

Thank you.


Site Timeline