Wiznet makers

ruilixin6

Published August 04, 2026 ©

74 UCC

0 VAR

0 Contests

0 Followers

0 Following

MicroPython Interrupt Guide: Supported & Unsupported Interrupts on Raspberry Pi Pico

Compares MicroPython v1.23.0 and v1.26.0 on RP2040, covering newly supported UART interrupts and trigger events to replace polling.

COMPONENTS
PROJECT DESCRIPTION

Tweet

1. Peripherals with interrupt function

In previous versions of MicroPython for the Raspberry Pi Pico (taking v1.23.0 as an example), only the following peripherals support interrupt functionality:
It can be seen that MicroPython's SDK does not provide interrupt functions for other peripherals, such as interrupt reception of the serial port, but this does not mean that we cannot use other methods to replace the polling method (using while loop to call UART. any () to determine whether there is data available for reception on the serial port). Instead, we can use methods such as timer-based regular serial port status query, multi-threading, and coroutines to complete the timely reception of serial port data more efficiently and accurately.
In the latest version of MicroPython for Raspberry Pi Pico (taking v1.26.0 as an example), interrupts for the newly added I2CTarget class and UART class are introduced, as shown in the table below:

2. Serial Port Interrupt Related Control Methods

UART. irq () is the core method for configuring serial port interrupts on the Pico. It is used to bind an interrupt handling function to a specified UART instance (such as UART0/UART1). When a preset event (such as receiving a character or an idle receive line) occurs on the serial port, this function will be automatically executed, eliminating the need for the main program to perform polling on the serial port status, thus greatly improving the response efficiency of the serial port.
The serial port interrupt method officially provided is as follows:
参数含义与 Pico 专属说明补充说明
handler可选,中断处理函数(仅接收1 个参数—— 触发中断的 UART 实例,如 UART0);设为None则禁用中断。
⚠️ Pico 注意:
1.hard=True时,函数禁止内存分配(如print()、创建列表 / 字符串拼接),否则系统崩溃;
2.hard=False(默认)限制宽松,但建议函数仅做核心操作(如缓存数据)。
trigger中断触发条件(可通过 `组合多个条件),Pico(RP2)支持的触发源及特性:
1. UART.IRQ_RXIDLE:接收≥1个字符后RX线空闲触发(适合处理完整数据段);
2. UART.IRQ_TXIDLE:仅当发送消息长度>5字符时触发,且触发时仍有5个字符待发送;
3. UART.IRQ_BREAK`:检测到 RX 线 Break 状态触发,触发后需接收有效字符才能再次触发。
hard中断类型:- False(默认):软中断(虚拟机处理,延迟稍高,限制少);- True:硬件中断(RP2040 硬件直驱,延迟极低,限制严格)。⚠️ Pico 完全支持该参数(区别于 ESP32)。
For the RP2040 corresponding to the Raspberry Pi Pico (the "RP2" row in the table), the UART interrupt trigger sources it supports are as follows:
IRQ_RXIDLE: Triggered when the RX line is idle after receiving ≥1 character (suitable for processing complete data segments);
IRQ_TXIDLE: It is triggered only when the length of the message to be sent is greater than 5 characters, and there are still 5 characters pending for transmission at the time of triggering;
IRQ_BREAK: Triggered when a Break state on the RX line is detected; after triggering, a valid character must be received before it can be triggered again.

 

 
Documents
Comments Write