[atmega8] Can't wake up from sleep mode



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.

.



Relevant Pages

  • [RFC] sleepy linux
    ... Download this big chunk in mozilla, then go to sleep ... but wake me up in 8:30 with mp3 player ... +void detect_idle; ... static int enter_state ...
    (Linux-Kernel)
  • Re: Waiting for a timer event in a console application?
    ... > Rather then Sleep, wake, check enabled, Sleep, wake, check enabled, ... > void TimerEvent ... >> presumably timer.Enabled is changed by the event handler? ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Waiting for a timer event in a console application?
    ... > Rather then Sleep, wake, check enabled, Sleep, wake, check enabled, ... > You can use a ManualResetEvent to signal the main thread when you have ... > void TimerEvent ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Why does Microsoft never document threading right?
    ... Because condition variables don't work very well on Win32, ... a few others) as well as events of various types (wake one, wake all, ... void Unlock ... {// best to call without lock ...
    (comp.programming.threads)
  • Re: pthread_cond_wait problem
    ... > state and won't wake up until thread 1 notifies it. ... This is my scenario ... void CCondition::Signal ...
    (comp.unix.programmer)