Interrupt still happening after detached (continue)

can’t figure out why when I run gfvalvo example

Serial.println(EIFR, BIN);
is working

But in my sketch

volatile byte flag0 = 0, flag1 = 0, eifr = 0;

void setup() {
  Serial.begin (115200);
  pinMode(2, INPUT_PULLUP);
  pinMode(3, INPUT_PULLUP);
  pinMode(13, OUTPUT);       //LED
  Serial.println ("go!");
  digitalWrite(13, HIGH);                 //time to go!

void loop() {
  delay (4000);
  eifr = EIFR;
  delay (100);
  Serial.println (eifr, DEC);
  Serial.println(EIFR, BIN);

  //EIFR = 1;
  // interrupt on
  attachInterrupt(0, isr0, FALLING);     //enable interrupt
  attachInterrupt(1, isr1, FALLING);     //enable interrupt

  // did we get an interrupt?
  Serial.print (flag0, DEC);
  Serial.print (flag1, DEC);
  Serial.print (" EIFR:");
  Serial.println (eifr, DEC);

  if (flag0){
  digitalWrite(13, !digitalRead(13));                 //time is up!
  flag0 = 0, flag1 = 0, eifr = 0;

void isr0 () {
  eifr = EIFR;
  flag0 = 1;
void isr1 () {
  eifr = EIFR;
  flag1 = 1;

Print EIFR is not working :frowning: why ???

There are lots of things wrong with that code, and part of it is missing, but first, you should learn that C/C++ is case sensitive.

A variable or object named EIFR is not the same as one named eifr.

The use of interrupts generally creates more problems than it solves, so avoid doing so unless necessary.

Thank you. I know this. and are you sure that reason why print is not workin in lower case name of variable ?
lower case was used special to declare my variable. BTW I also have used direct print as in gfvalvo example. it also is not workin.

You have not told us what “not working” means.

Tell us what you expect to happen, and what happens instead.

Pls look at #1 post

But in my sketch, the same print is not working. why?

See reply #4.

pls look at the code and to linked thread. we are talking about EIFR… how to read/write/clear/print…

  1. in gfvalvo example print EIFR is workin - it show us correct value …

  2. in my example (mostly the same as gfvalvo) print EIFR always is 0

Did you create global variables? (as the supplied code throws error if not)

volatile uint8_t eifr;
volatile boolean flag0, flag1;

sure. sorry copy/past lost it… :slight_smile:
but as I can see you addit it self.
Once more time I have no error
just print EIFR always printing 0 even where should print 1. why?

finally , I figured out... I tried to catch EIFR in loop() and when interrupt was rised/attached but due to fact that most of time it clear before we enter to ISR ... so I couldnt catch it.
In gfvalvo example , he do not attach INT just print EIFR

So, after few checks of EIFR and INT, want to add some comments to this topic

Dave: The interrupt flag is automatically reset when the program returns from the ISR.

my test shows its reset before or at the same time when we enter in the ISR. 80% of time its clearing before we enter to ISR

Nick: However more accurately than what either of us suggested you should "or" it in (or you have the effect of clearing the other interrupt flag, almost certainly what you don't want).

my test shows, we can put logical one (for INT0) with any available methods (even as EIFR |= 4%3;) INT0 will be cleared. Sure INT1 also can be cleared due to ORing. But if in our project is used only INT0 this is not a problem. Otherwise (if problem) we should use direct writing EIFR = 1;

Nick: Just in case there is an interrupt between reading EIFR and or'ing in the new value.

Im not profi as Nick Dave or Coding_Badly but if we want avoid this scenario then we should not "or"ing as you suggested before... we should put directly , like EIFR = 1;

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.