Interrupts

17391939:
BTW I have read all the documentation on interrupts widely.

The you should have read how the interrupt trigger type (rising, falling, etc) and other characteristics can be changed through direct manipulation of the registers defined in Chapter 13 of the ATmega328P datasheet. Calling attachInterrupt() inside the ISR is uncalled for.

gfvalvo:
Calling attachInterrupt() inside the ISR is uncalled for.

I believe what I suggested in Reply #16 provides a solution within the scope of the OP's current programming knowledge.

...R

Robin2:
I believe what I suggested in Reply #16 provides a solution within the scope of the OP's current programming knowledge.

...R

Perhaps. I haven't dug deeply into OP's code. But I do see that the various repeated calls to attachInterrupt() change the mode between RISING and FALLING. If that's really necessary, the appropriate way is with the EICRA register before returning from the ISR. You could also use the CHANGE mode, but then a read (preferably directly via the PINx register) would be needed to know the cause of the interrupt (falling / rising). Regardless, calling attachInterrupt() is NOT the way to do it.

gfvalvo:
But I do see that the various repeated calls to attachInterrupt() change the mode between RISING and FALLING.

I confess I had not spotted that.

As you say, the CHANGE mode might be more appropriate and test within the ISR whether the pin is actually HIGH or LOW

...R

aarg:
An attachInterrupt() call inside an ISR. You've got a lot of explaining to do...

I agree, but I I'm unsure on how to explain

17391939:
I agree, but I I'm unsure on how to explain

Tell us what you want to happen, not how you think it should be done.

...R

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