This shows you the differences between two versions of the page.
eap:laboratoare:02 [2024/07/17 17:43] jan.vaduva [Interrupts] |
eap:laboratoare:02 [2024/07/18 10:08] (current) jan.vaduva |
||
---|---|---|---|
Line 1: | Line 1: | ||
- | ===== RP2040 internals ===== | + | ===== RP2040 internals: UART, interrupts & timers ===== |
==== UART ==== | ==== UART ==== | ||
Line 174: | Line 174: | ||
INTR. | INTR. | ||
- | Here's a basic introduction to using timers on RP2040 with Pico-SDK. | + | For using timers on RP2040 with Pico-SDK include the hardware/timer.h header from Pico-SDK: |
- | * In your C/C++ code, include the hardware/timer.h header from Pico-SDK: | + | |
<code> | <code> | ||
#include <hardware/timer.h> | #include <hardware/timer.h> | ||
- | </code> | ||
- | * Globally enable interrupts using the **irq_set_enabled(true)** function. This allows the RP2040 to recognize and respond to interrupt requests. Various hardware events can trigger interrupts, like changes on GPIO pins, timers expiring, or DMA transfers completing. | ||
- | <code> | ||
- | // Set up a RX interrupt | ||
- | int UART_IRQ = UART_ID == uart0 ? UART0_IRQ : UART1_IRQ; | ||
- | |||
- | // And set up and enable the interrupt handlers | ||
- | irq_set_exclusive_handler(UART_IRQ, on_uart_rx); | ||
- | irq_set_enabled(UART_IRQ, true); | ||
- | </code> | ||
- | * Define a function to handle the interrupt. This function is called whenever the configured trigger source (e.g., the GPIO pin change) occurs. The handler function can perform actions like reading the GPIO pin state, triggering other events, or notifying other parts of your program about the interrupt. | ||
- | <code> | ||
- | // RX interrupt handler | ||
- | void on_uart_rx() { | ||
- | // Perform action based on the interrupt | ||
- | | ||
- | // Clear the interrupt flag (important) | ||
- | } | ||
</code> | </code> | ||
==== Exercises ==== | ==== Exercises ==== |