Go Down

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

ytorroja

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

Coding Badly


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

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!

Arduino
via Egeo 16
Torino, 10131
Italy