Hi, i am using an interrupt triggered function. It should be fired as soon as the signal on the interrupt Pin is changing, but there is an unwanted begin of the function as soon as i attach the interrupt. I think it has nothng to do with noise on the pin, because the unwanted interrupt start only happens at this one moment- afterwars the interrupt is doing what it should. I tried changing the trigger event (FALLING, RISING, CHANGE), but always the same. Here is my (simplified) code (i am using a Due):
@Robin2
Why not serial-Printing inside ISR? Even not for debugging?
Thanks for the tip with the flag. I didn‘t start anything which should have changed the value of the pin. I don‘t exactly understand what you mean with „flag“ in this context. I thought a digital pin simply has its value- either low or high, and this state (or change of the state) triggers the ISR. Where can i find and change this „hidden“ flag?
Hahi:
Why not serial-Printing inside ISR? Even not for debugging?
Because inside an interrupt handler all interrupts and other code is interrupted. Serial communication uses interrupts for transmitting and since they are not available, this may cause unwanted behaviour.
Setting the pin high via INPUT_PULLUP is a change on the pin, I think this causes an
immediate interrupt when you enable it. If you want to ignore this, you'll have to
explicitly code that in the ISR itself. Or you can explicitly cancel the interrupt
flag in the registers for that pin.
Check the datasheet section for the real details though...
Thank You for the explanation, i think, thats also what Robin2 wanted to tell me before. Just for testing purposes i simply made a dummy ISR and detached it during setup and really, since then there is no such behavior when i attach my "real" ISR. Now i need to code it properly, cancelling the interrupt flag, but thats another topic...
Thanks a lot, that was a quick solution
MarkT:
Setting the pin high via INPUT_PULLUP is a change on the pin, I think this causes an
immediate interrupt when you enable it.