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

Hi,

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);
      break;
  ... and so on
  ...

Thanks :-)

Yago
Logged

Global Moderator
Dallas
Offline Offline
Shannon Member
*****
Karma: 200
Posts: 12773
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset


Please create an issue...
http://code.google.com/p/arduino/issues/list
Logged

Pages: [1]   Go Up
Jump to: