class ExtInt – configure I/O pins to interrupt on external events¶
STM32 MCUs split the external interrupt controller (EXTI) into two ranges: lines 0-15 are driven from GPIO pins, and the lines above 15 are tied to internal sources (RTC alarm, RTC wakeup, USB wakeup, etc.). The total line count and the mapping of internal lines above 15 are MCU-specific; consult the EXTI section of the reference manual for the OpenMV Cam’s MCU for the exact assignments.
Each GPIO line N can be driven by pin PxN on any one GPIO port at a
time – for example line 0 may map to PA0, PB0, PC0 or any
other port-A through port-K pin 0, but only one at a time.
Example:
def callback(line):
print("line =", line)
extint = pyb.ExtInt(pin, pyb.ExtInt.IRQ_FALLING, pyb.Pin.PULL_UP, callback)
Every falling edge on pin then invokes callback. ExtInt
automatically configures the GPIO line as an input; you do not need to do
that yourself.
Note
Mechanical pushbuttons “bounce” and a single press or release often generates multiple edges. See for example this debouncing primer for techniques.
Registering two callbacks on the same pin raises an exception.
If pin is passed as an integer it is assumed to identify one of the
internal interrupt lines and must be >= 16 and below the MCU’s total
EXTI line count. Any other pin value is resolved through the standard
pin mapper.
In addition to the IRQ_* modes there are EVT_RISING, EVT_FALLING
and EVT_RISING_FALLING event modes that route a transition to the
processor’s event input (used with the WFE instruction for low-power
wait). The EVT_* modes do not invoke the Python callback and are
intended for sleep / power-management use; ordinary application code
should use the IRQ_* modes.
Constructors¶
- class pyb.ExtInt(pin: int | str | Pin, mode: int, pull: int, callback: Callable[[int], None])¶
Create an
ExtIntobject.pin– the pin to enable the interrupt on. May be aPinobject, a pin-name string, or an integer in the range16-21to select an internal interrupt source.mode– the trigger mode. One of:Constant
Trigger
Rising edge.
Falling edge.
Either rising or falling edge.
pull– the pin pull configuration. One ofpyb.Pin.PULL_NONE,pyb.Pin.PULL_UPorpyb.Pin.PULL_DOWN.callback– callable invoked on the trigger. Must accept exactly one argument: the EXTI line number that fired.
Class methods¶
Methods¶
Constants¶