1. This forum section is a read-only archive which contains old newsgroup posts. If you wish to post a query, please do so in one of our main forum sections (here). This way you will get a faster, better response from the members on Motherboard Point.

[atmega8] Can't wake up from sleep mode

Discussion in 'Embedded' started by ilovecpp, Jul 21, 2005.

  1. ilovecpp

    ilovecpp Guest

    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.
     
    ilovecpp, Jul 21, 2005
    #1
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.