-1

How make by C-SDK same Rpi Pico receiving on multiple UARTs

1 Answer 1

1

To enable the Raspberry Pi Pico to receive data on multiple UARTs using the C-SDK, you'll need to configure and initialize each UART interface separately. Here is an example code:

#include <stdio.h>
#include "pico/stdlib.h"
#include "hardware/uart.h"

#define UART1_ID uart0
#define UART1_TX_PIN 0
#define UART1_RX_PIN 1
#define UART1_BAUD_RATE 9600

#define UART2_ID uart1
#define UART2_TX_PIN 2
#define UART2_RX_PIN 3
#define UART2_BAUD_RATE 115200

int main() {
    stdio_init_all();

    // Initialize UART1
    uart_init(UART1_ID, UART1_BAUD_RATE);
    gpio_set_function(UART1_TX_PIN, GPIO_FUNC_UART);
    gpio_set_function(UART1_RX_PIN, GPIO_FUNC_UART);
    uart_set_hw_flow(UART1_ID, false, false);

    // Initialize UART2
    uart_init(UART2_ID, UART2_BAUD_RATE);
    gpio_set_function(UART2_TX_PIN, GPIO_FUNC_UART);
    gpio_set_function(UART2_RX_PIN, GPIO_FUNC_UART);
    uart_set_hw_flow(UART2_ID, false, false);

    while(1) {
        // Receive data on UART1
        if(uart_is_readable(UART1_ID)) {
            printf("Received on UART1: %c\n", uart_getc(UART1_ID));
        }

        // Receive data on UART2
        if(uart_is_readable(UART2_ID)) {
            printf("Received on UART2: %c\n", uart_getc(UART2_ID));
        }
    }

    return 0;
}
6
  • Thank you for the information. information Commented Mar 24 at 11:41
  • What I'm looking for is a total of 4 RX UARTs, and I want to achieve this with PIO. Commented Mar 24 at 11:42
  • PIO pio = pio1; // values: pio0, pio1 uint pin = 20; // 26PIN rx pin. Any gpio is valid uint irq = PIO1_IRQ_0; // values for pio0: PIO0_IRQ_0, PIO0_IRQ_1. values for pio1: PIO1_IRQ_0, PIO1_IRQ_1 uint baudrate = 9600; uart_rx_init(pio, pin, baudrate, irq); uart_rx_set_handler(rx_handler); Commented Mar 24 at 11:43
  • PIO pio2 = pio0; // values: pio0, pio1 pin = 21; // 27PIN rx pin. Any gpio is valid irq = PIO0_IRQ_0; // values for pio0: PIO0_IRQ_0, PIO0_IRQ_1. values for pio1: PIO1_IRQ_0, PIO1_IRQ_1 baudrate = 19200; uart_rx_init(pio2, pin, baudrate, irq); uart_rx_set_handler(rx_handler2); Commented Mar 24 at 11:44
  • It doesn't work when I use two PIOs, but it works when I use them individually.What should I do? Commented Mar 24 at 11:44

Not the answer you're looking for? Browse other questions tagged or ask your own question.