clear interrupt flag - how is it done?

as i understand it, an interrupt flag is something stored in memory that says an interrupt has been triggered. how do i clear (reset?) the flag?

potentially unnecessary info:
right now i have it set so that when i hit a button it calls a function via interrupt and right away detaches the interrupt. unfortunately when i later re-attach it calls the function one more time regardless of how long of a delay i have in the re-attaching.

Hi,

normally the interrupt flag is reset automatically, when the interrupt handler is called. It can be cleared by software by writing a 1 to the interrupt flag (see datasheet of the MCU for the register names and bit positions of all the different interrupt flags).

Mike

Thanks Mike. I do need some more help though. I don't know what to do with the information, never used the atmega info directly. How do I write a "logical one" to the INTF1 or INTF2 (and is that what I am supposed to do?)? I take it I write "00000001" for INTF1 and "00000010" for INTF2, but not sure how to do that. Do I add the atmega i/o header then just do something like "int INTF1 = B00000001"?

I have the ATMega168:
VectorNo. Program Address Source Interrupt Definition
1 0x0000 RESET External Pin, Power-on Reset, Brown-out Reset and Watchdog System Reset
2 0x0002 INT0 External Interrupt Request 0
3 0x0004 INT1 External Interrupt Request 1

Interrupt Flag info:

12.2.3 EIFR – External Interrupt Flag Register
? Bit 7..2 – Res: Reserved Bits
These bits are unused bits in the ATmega48/88/168, and will always read as zero.
? Bit 1 – INTF1: External Interrupt Flag 1
When an edge or logic change on the INT1 pin triggers an interrupt request, INTF1 becomes set
(one). If the I-bit in SREG and the INT1 bit in EIMSK are set (one), the MCU will jump to the corresponding
Interrupt Vector. The flag is cleared when the interrupt routine is executed.
Alternatively, the flag can be cleared by writing a logical one to it. This flag is always cleared
when INT1 is configured as a level interrupt.
? Bit 0 – INTF0: External Interrupt Flag 0
When an edge or logic change on the INT0 pin triggers an interrupt request, INTF0 becomes set
(one). If the I-bit in SREG and the INT0 bit in EIMSK are set (one), the MCU will jump to the corresponding
Interrupt Vector. The flag is cleared when the interrupt routine is executed.
Alternatively, the flag can be cleared by writing a logical one to it. This flag is always cleared
when INT0 is configured as a level interrupt.

Sounds like this may be what is happening in my code:
"Interrupt Flags can also be cleared by writing a logic one to the flag bit position(s) to be cleared. If an interrupt condition occurs while the corresponding interrupt enable bit is cleared, the Interrupt Flag will be set and remembered until the interrupt is enabled, or the flag is
cleared by software."

Looking at this:

Address Name Bits(7->0)
0x1C (0x3C) EIFR – – – – – – INTF1 INTF0

it seems that i need to do something like "EIFR = 0x01" to clear interrupt 0 flag. i'm mostly confused on how to write the code statement and how to access certain bits (i.e. how i write a 1 to bit 0 or bit 1).

Hi,

sorry for the late reply, but that is eactly what to do to reset the INT0 Flag

EIFR = 0x01;

Mike

np, thanks for replying.

do i need to add avr/io.h in order to use that or some other header file? i tried using that with io.h and interrupt.h and with no extra .h file and i didn't see a difference. although i didn't try setting it up where it would definitely make a difference (i.e. having it clear original flag before it called a function to see if it prevented function from being called).

i did however figure out how to debounce via software so i no longer need to use that, but it would be good to know what i need to include in order to use that command.