Pages: [1]   Go Down
Author Topic: attachInterrupt(...) improvement  (Read 731 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Karma: 0
Posts: 1
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset


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 :-)


Global Moderator
Online Online
Shannon Member
Karma: 212
Posts: 13072
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Please create an issue...

Pages: [1]   Go Up
Jump to: