Simple Interrupt Problem
Posted: Sun Oct 30, 2016 1:35 pm
I was working on a significantly more complex programs and having some problems that I traced back to the fact that the interrupt wasn't firing.
I've written a new, extremely simple program just to prove to myself that I can make interrupts work, and its not going so well.
it uses the user button on the expansion board to trigger interrupts to increment a counter (or at least that's the idea)
here's the contents of boot.py, there is no main.py:
[code]
import micropython
from machine import Pin
micropython.alloc_emergency_exception_buf(100)
int_counter =0
def int_handler():
global int_counter
int_counter+=1
button=Pin('GP17', mode=Pin.IN, pull=Pin.PULL_UP)
button.irq(trigger=Pin.IRQ_RISING|Pin.IRQ_FALLING, handler=int_handler)
[/code]
I know the pin setup is working because when I go to the repl and run button() I get a value that toggles as I press and release the button
I know the handler function works because when I manually run int_handler(), int_counter increments.
Further, I suspect the trigger is working because when I press the button for the first time, the heartbeat LED blinks very rapidly for a couple seconds. However it won't do that again unless the button.irq() method is re-called.
However, when I press the button, int_counter does not increment.
Any idea what's going on here? I'm stumped
I've written a new, extremely simple program just to prove to myself that I can make interrupts work, and its not going so well.
it uses the user button on the expansion board to trigger interrupts to increment a counter (or at least that's the idea)
here's the contents of boot.py, there is no main.py:
[code]
import micropython
from machine import Pin
micropython.alloc_emergency_exception_buf(100)
int_counter =0
def int_handler():
global int_counter
int_counter+=1
button=Pin('GP17', mode=Pin.IN, pull=Pin.PULL_UP)
button.irq(trigger=Pin.IRQ_RISING|Pin.IRQ_FALLING, handler=int_handler)
[/code]
I know the pin setup is working because when I go to the repl and run button() I get a value that toggles as I press and release the button
I know the handler function works because when I manually run int_handler(), int_counter increments.
Further, I suspect the trigger is working because when I press the button for the first time, the heartbeat LED blinks very rapidly for a couple seconds. However it won't do that again unless the button.irq() method is re-called.
However, when I press the button, int_counter does not increment.
Any idea what's going on here? I'm stumped