This is an old revision of the document!


RP2040 internals

UART

The RP2040 microcontroller from Raspberry Pi offers two built-in UART peripherals for serial communication. Here's a basic introduction to using UART with Pico-SDK, including configuration, sending, and receiving data:

  • Include necessary libraries: In your C/C++ code, include the hardware/uart.h header from Pico-SDK:
#include <hardware/uart.h>
  • Initialize UART: Use the uart_init function to configure the desired UART peripheral (e.g., uart0 or uart1) and set parameters like baud rate, parity, and stop bits:
// Example: Configure UART0 at 115200 baud, 8N1 format
int baudrate = 115200;
uart_init(uart0, baudrate, UART_PARITY_NONE, UART_STOP_BITS_1);
  • Prepare data: The data you want to send must be an array of characters (char*).
  • Transmit data: Use the uart_puts function for sending a null-terminated string (\0 at the end). Alternatively, uart_write_blocking offers more control over the data buffer and transmission:
const char* message = "Hello from RP2040!\n";

// Example 1: Sending a string with uart_puts
uart_puts(uart0, message);

// Example 2: Sending raw data with uart_write_blocking
uint8_t data[] = {0x41, 0x42, 0x43};  // Example data bytes
int written = uart_write_blocking(uart0, data, sizeof(data));
  • dad

Interrupts

Timers

Exercises

  1. Write a program for a Raspberry Pi Pico to communicate with another device via UART. The program will set up the UART with desired settings, send a predefined message, receive incoming data, and process it (like printing or storing).
  2. Prepare your setup for Marble Pico interaction with VS Code and pico SDK or use Arduino IDE support according to instructions available here: Ardushop Marble Pico.

References

eap/laboratoare/02.1721221067.txt.gz ยท Last modified: 2024/07/17 15:57 by jan.vaduva
CC Attribution-Share Alike 3.0 Unported
www.chimeric.de Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0