Go Down

Topic: attachInterrupt() calls wrong function upon interrupt on Arduino Mega2650 (Read 1 time) previous topic - next topic


I agree with you that Serial.printLn has no place in an interrupt. However in this particular case it was not printing enough to fill the buffer (64 bytes) and the interrupt is hardly ever triggered (once every hour or so). It was added in order to help with debugging. The same problem exists regardless of whether there is a print statement or not in the interrupt.


and the interrupt is hardly ever triggered (once every hour or so).

Then, why do you need interrupts? Interrupts are for things that have to be noticed RIGHT NOW! Once an hour is not something that needs to be dealt with immediately.


What board are you compiling for? Because when I compile your code I get the following IVT:

Code: [Select]

00000000 <__vectors>:
   0: 71 c0        rjmp .+226    ; 0xe4 <__ctors_end>
   2: 00 00        nop
   4: 57 c1        rjmp .+686    ; 0x2b4 <__vector_1>
   6: 00 00        nop
   8: 86 c1        rjmp .+780    ; 0x316 <__vector_2>
   a: 00 00        nop
   c: b5 c1        rjmp .+874    ; 0x378 <__vector_3>
   e: 00 00        nop
  10: e4 c1        rjmp .+968    ; 0x3da <__vector_4>
  12: 00 00        nop
  14: 13 c2        rjmp .+1062    ; 0x43c <__vector_5>
  16: 00 00        nop
  18: 42 c2        rjmp .+1156    ; 0x49e <__vector_6>
  1a: 00 00        nop
  1c: 71 c2        rjmp .+1250    ; 0x500 <__vector_7>
  1e: 00 00        nop
  20: a0 c2        rjmp .+1344    ; 0x562 <__vector_8>
  22: 00 00        nop
  24: 7f c0        rjmp .+254    ; 0x124 <__bad_interrupt>


I just tested those interrupts on my Mega, and they work fine. There was one surprise I had not noticed before. The two interrupt functions are called once by the "attachInterrupt()" function before any interrupts occur.

edit: What type of circuit are you using to trigger the interrupts? I'm using D25 (output) wired to D21 and D26 (output) wired to D20.


I compiled it for the atmega2560. Its strange that it would work fine for you SurferTim and not me. Thanks for the info though. I'll have to go back and see whether I can figure out what the deal is with my setup. Could you tell me which IDE version you are running? I tried it with multiple arduino megas and had the same result.
Thanks for the help.

PaulS -
Just because a hardware interrupt only triggers once every hour doesn't mean that when it does it doesn't need to be serviced immediately. For instance this one services limit switches on a gantry. If the stepper hits the limit, it needs to stop RIGHT NOW.

Go Up