uart_poll_in not receiving data

Hello,

I'd like to send/receive data over UART using the expansion board connector of my Thingy:91 X (pins 0.18 & 0.19 as RX/TX). With SB8&9 separated (to isolate pins from I2C), I can without problems send messages using uart_poll_out and read them with another device. However, I never receive anything with uart_poll_in, although I can measure the UART signal on TP32/33 with an oscilloscope. I've also tried to switch the pins in the overlay and on hardware side, but still - sending works, receiving not. Attached my code, could you please support?

Thanks,
Simon

20602.prj.conf

#include <zephyr/kernel.h>
#include <zephyr/device.h>
#include <zephyr/drivers/uart.h>
#include <string.h>

#define UART_NODE DT_NODELABEL(uart0)
#define RX_BUF_SIZE 128

/* Simple helper to send strings over UART using poll_out */
static void uart_send(const struct device *dev, const char *msg)
{
    while (*msg) {
        uart_poll_out(dev, *msg++);
    }
}

/* Add CRLF for nicer formatting */
static void uart_send_line(const struct device *dev, const char *msg)
{
    uart_send(dev, msg);
    uart_poll_out(dev, '\r');
    uart_poll_out(dev, '\n');
}

void main(void)
{
    const struct device *uart_dev = DEVICE_DT_GET(UART_NODE);

    if (!device_is_ready(uart_dev)) {
        /* If UART not ready, we can’t print anywhere else */
        return;
    }

    uart_send_line(uart_dev, "UART echo example started!");
    uart_send_line(uart_dev, "Type something and press Enter...");

    uint8_t c;
    char rx_buf[RX_BUF_SIZE];
    size_t idx = 0;

    while (1) {
        /* Non-blocking read of one character */
        if (uart_poll_in(uart_dev, &c) == 0) {

            if (c == '\r' || c == '\n') {
                if (idx > 0) {
                    rx_buf[idx] = '\0';

                    uart_send(uart_dev, "Echo: ");
                    uart_send_line(uart_dev, rx_buf);

                    idx = 0; // reset buffer
                }
            } else if (idx < sizeof(rx_buf) - 1) {
                rx_buf[idx++] = c;
                uart_poll_out(uart_dev, c);  // local echo while typing
            }

        } else {
            k_sleep(K_MSEC(10));  // avoid busy loop
        }
    }
}
8880.thingy91x_nrf9151_ns.overlay

Parents Reply Children
Related