Forum: Mikrocontroller und Digitale Elektronik Timer2 Interrupt funktioniert nicht


von f.h. (Gast)


Lesenswert?

Ich habe einen Atmega88 mit externen Quarz im Einsatz und benötige einen 
Interrupt jede Sekunde vom Timer2:

Ich finde den Fehler nicht:

void timer2 (void)
{

cli();             // disable global interrupts
TIMSK2 = 0x00;  //1. Disable the Timer/Counter2 interrupts clear
ASSR = (1<<AS2);  //2. Select clock source by setting AS2 as 
appropriate. TCNT2 = 0x00;        //3.  Timer2 = 0
TCCR2B |= (1<<CS22) | (1<<CS20);  // select prescaler: 32.768 kHz/128=1
                                  //sec between each overflow

// 4. To switch to asynchronous operation: Wait for TCN2UB, OCR2UB, and
//    TCR2UB.

while( (ASSR & (1<<TCN2UB)) | (ASSR & (1<<OCR2AUB)) |
        (ASSR & (1<<TCR2BUB)) );


// 5. Clear the Timer/Counter2 Interrupt Flags.
TIFR2 |= ((1<<OCF2A)|(1<<TOV2));


// 6. enable Timer2 Overflow interrupt
TIMSK2 |= (1<<TOIE2);
sei();
}

Bitte melde dich an um einen Beitrag zu schreiben. Anmeldung ist kostenlos und dauert nur eine Minute.
Bestehender Account
Schon ein Account bei Google/GoogleMail? Keine Anmeldung erforderlich!
Mit Google-Account einloggen
Noch kein Account? Hier anmelden.