Go Down

Topic: attachInterrupt(...) improvement (Read 802 times) previous topic - next topic



I have observed that attachInterrupt() does not clear the interrupt flag before doing the "attachment". I think it would be a good idea to do it. Otherwise, pending interrupts could be executed immediatly after calling attachInterrupt(). Although we could discuss a lot about it, I would say 95% of cases this would not be the desired behavior, specially taking into account the average Arduino user. 

This can be easily done in the file WInterrupts.c, clearing the interrupt flag before the mask activation, i.e.

void attachInterrupt(uint8_t interruptNum, void (*userFunc)(void), int mode) {
    switch (interruptNum) {
#if defined(EICRA) && defined(EICRB) && defined(EIMSK)
    case 2:
      EICRA = (EICRA & ~((1 << ISC00) | (1 << ISC01))) | (mode << ISC00);
      EIFR |= (1 << INT0);  <<<<<<<<<<<<<<<<<<<<<<<<<<  pending interrupt clearing
      EIMSK |= (1 << INT0);
  ... and so on

Thanks :-)


Coding Badly

Please create an issue...

Go Up

Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

via Egeo 16
Torino, 10131