Clearing Interrupts

Go To Last Post
3 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0
  #include 
  #include  
  ISR(TIMER1_COMPA_vect)
	{PORTD ^=(1<<1);
	 
	};
  void main(void)
  { 
    DDRD |= (1<<1); //Make Pin 1 on PortD an output
    TCCR1B |= (1<<CS12); //1024/20Mhz=0.0000512 seconds
    TCCR1B |= (1<<CS10); //
	TCCR1B |= (1 << WGM12);
	OCR1A=19531; //To get a one second interrupt.
	TIMSK1 |=(1<<OCIE1A);//Enable interrupts???/
	SREG   |=(1<<7); //Enable Global Interrupts
    
	while(1)
    {
    
    }

    
	
	
  }

Why does this work? I thought you had to clear the interrupt bit but in the code I wrote I don't clear anything.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Most interrupt conditions are auto-clearing when the appropriate
ISR is invoked. Notable exceptions include UART interrupts (the
Rx and Tx interrupts are cleared when accessing UDR, the UDRE
interrupt is never cleared and must be turned off when not needed),
and the TWI interrupt as clearing the interrupt flag there causes
a TWI transaction.

Jörg Wunsch

Please don't send me PMs, use email if you want to approach me personally.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Correct me if I'm wrong, but isn't the UDRE interrupt flag clear when there is data in the UART transmit buffer? That way you can use the UDRE interrupt as a way to empty out a UART_transmit buffer variable?

Also, just to add on to what Jörg said, there are a few other exceptions where interrupt flags are not automatically reset. When dealing with AT90CAN128 microcontrollers, the interrupt flags of the CANSTMOB register must be manually reset in the CANIT_vect interrupt using read-modify-writes.