VideoLibrary

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.

3/23/2026 1:37:35 PM

Part List

ImageManufacturer Part NumberDescriptionAvailable QuantityPriceView Details
RASPBERRY PI PICO 2 RP2350SC1631RASPBERRY PI PICO 2 RP235026210 - Immediate$45.14View Details
RASPBERRY PI PICO 2 H RP2350SC1632RASPBERRY PI PICO 2 H RP23501693 - Immediate$54.17View Details
RASPBERRY PI PICO 2 W RP2350SC1633RASPBERRY PI PICO 2 W RP23506111 - Immediate$63.20View Details
RASPBERRY PI PICO 2 WH RP2350SC1634RASPBERRY PI PICO 2 WH RP23502388 - Immediate$72.23View Details
RES 220 OHM 5% 1/4W AXIALCF14JT220RRES 220 OHM 5% 1/4W AXIAL93369 - Immediate
30000 - Factory Stock
$0.90View Details
USB AM TO USB MICRO, USB 2.0 - 1DH-20M50055USB AM TO USB MICRO, USB 2.0 - 19354 - Immediate$13.99View Details
JUMPER WIRE M TO M 6" 28AWG1957JUMPER WIRE M TO M 6" 28AWG3907 - Immediate$17.61View Details
BREADBRD TERM STRIP 3.20X2.00"FIT0096BREADBRD TERM STRIP 3.20X2.00"3713 - Immediate$26.18View Details
SWITCH TACTILE SPST-NO 0.05A 24V1825910-6SWITCH TACTILE SPST-NO 0.05A 24V45941 - Immediate$1.17View Details
LED RED CLEAR T-1 3/4 T/HLTL-4224LED RED CLEAR T-1 3/4 T/H73475 - Immediate$1.26View Details
TMP102 DIGITAL TEMP SENSOR BOARD13314TMP102 DIGITAL TEMP SENSOR BOARD254 - Immediate$53.72View Details