Intro to Embedded Rust Part 10: Interrupts | DigiKey
In this tutorial, we demonstrate how to use hardware interrupts in embedded Rust on the Raspberry Pi 2. The written guide for this episode can be found here: https://www.digikey.com/en/maker/tutorials/2026/intro-to-embedded-rust-part-10-interrupts The GitHub repository containing the Docker image and example code for this series can be found here: https://github.com/ShawnHymel/introduction-to-embedded-rust Interrupts are a fundamental mechanism in embedded systems that allow the processor to pause normal execution to handle time-critical events, then automatically resume where it left off. Without interrupts, programs must constantly poll peripherals to detect events, which is often a wasteful approach that keeps the processor busy and prevents power-saving sleep modes. We demonstrate interrupt-driven programming by creating a blinking LED application where a timer alarm triggers interrupts every 500 milliseconds while the main program sleeps, showcasing how interrupts enable responsive, power-efficient embedded applications. You'll learn how to configure timer alarms, write interrupt service routines (ISRs), manage the Nested Vectored Interrupt Controller (NVIC), and safely share data between main code and interrupt handlers using Rust's type system. We’ll show how interrupts work: when an event occurs, the processor saves its state, jumps to an interrupt service routine to handle the event quickly, then returns to normal execution. We demonstrate a critical challenge in concurrent programming in embedded systems: safely accessing shared data between interrupt handlers and main code. We introduce the Mutex<RefCell<Option<T>>> pattern, which combines critical sections (disabling interrupts temporarily), interior mutability (RefCell for runtime borrow checking), and optional values to safely share peripherals like timer alarms and GPIO pins between different execution contexts. We show how to configure timer interrupts on the RP2350 using the rp235x-hal crate. You'll learn to create timer alarms with hal::Timer::new_timer0() and schedule them using the fugit crate's convenient duration types like MicrosDurationU32::millis(500). We demonstrate enabling interrupt sources, unmasking interrupts in the NVIC with NVIC::unmask(), and writing ISRs with the #[interrupt] attribute that automatically registers them in the interrupt vector table. The tutorial covers ISR best practices: clearing interrupt flags to acknowledge events, keeping handlers short and fast, rescheduling repeating events, and using wfi() (wait for interrupt) in the main loop for power efficiency. You'll see how proper interrupt-driven design allows the processor to sleep 99% of the time while still maintaining precise timing, dramatically reducing power consumption compared to polling approaches. At the end of the episode, we issue you a challenge to implement an external interrupt (based on a button press) based on what you’ve learned in the video.
Part List
| Image | Manufacturer Part Number | Description | Available Quantity | Price | View Details | |
|---|---|---|---|---|---|---|
![]() | ![]() | SC1631 | RASPBERRY PI PICO 2 RP2350 | 26224 - Immediate | $4.28 | View Details |
![]() | ![]() | SC1632 | RASPBERRY PI PICO 2 H RP2350 | 1801 - Immediate | $5.14 | View Details |
![]() | ![]() | SC1633 | RASPBERRY PI PICO 2 W RP2350 | 6134 - Immediate | $5.99 | View Details |
![]() | ![]() | SC1634 | RASPBERRY PI PICO 2 WH RP2350 | 2392 - Immediate | $6.85 | View Details |
![]() | ![]() | CF14JT220R | RES 220 OHM 5% 1/4W AXIAL | 93395 - Immediate 30000 - Factory Stock | $0.09 | View Details |
![]() | ![]() | DH-20M50055 | USB AM TO USB MICRO, USB 2.0 - 1 | 9361 - Immediate | $1.33 | View Details |
![]() | ![]() | 1957 | JUMPER WIRE M TO M 6" 28AWG | 3915 - Immediate | $1.67 | View Details |
![]() | ![]() | FIT0096 | BREADBRD TERM STRIP 3.20X2.00" | 4641 - Immediate | $2.48 | View Details |
![]() | ![]() | 1825910-6 | SWITCH TACTILE SPST-NO 0.05A 24V | 47998 - Immediate | $0.11 | View Details |
![]() | ![]() | LTL-4224 | LED RED CLEAR T-1 3/4 T/H | 73475 - Immediate | $0.12 | View Details |
![]() | ![]() | 13314 | TMP102 DIGITAL TEMP SENSOR BOARD | 254 - Immediate | $5.09 | View Details |
















