ESP-IDF on ESP32-C6: Can receive characters via UART1, but not UART0

63 Views Asked by At

I am using ESP-IDF on a ESP-32 dev kit (ESP32-C6-DevKitC-1), and trying to establish basic UART comms. I've started with the wifi/scan example, which runs fine. The pin layout, for reference, is here:

https://docs.espressif.com/projects/espressif-esp-dev-kits/en/latest/_images/esp32-c6-devkitc-1-pin-layout.png

I'm able to both send and receive over UART1 via Pins 10 and 11 using this code:

void UART_Initialize_WorksOn10and11()
{
    uart_config_t uart_config = {
        .baud_rate = 115200,
        .data_bits = UART_DATA_8_BITS,
        .parity    = UART_PARITY_DISABLE,
        .stop_bits = UART_STOP_BITS_1,
        .flow_ctrl = UART_HW_FLOWCTRL_DISABLE,
        .source_clk = UART_SCLK_DEFAULT,
    };

    SMILE_UART_NUM = UART_NUM_1;

    esp_err_t r;

    const int uart_buffer_size = (1024 * 2);
    QueueHandle_t uart_queue;

    r = uart_driver_install(SMILE_UART_NUM, uart_buffer_size, uart_buffer_size, 10, NULL, 0);
    r = uart_param_config(SMILE_UART_NUM, &uart_config);
    r = uart_set_pin(SMILE_UART_NUM, 11,10, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE); 
}

void UART_ReadLoop()
{
    int reported_length = 0;
    esp_err_t r;
    r = uart_get_buffered_data_len(SMILE_UART_NUM, (size_t*)&reported_length);
    int bytes_to_read = reported_length;
    int bytes_read = uart_read_bytes(SMILE_UART_NUM, m_RxBuffer, reported_length, 0);

    if (bytes_read > 0)
    {
        printf("Read '%s'\n", m_RxBuffer);
    }
}

But when I switch to UART0, using this code:

void UART_Initialize_DoesntWorkOnUART0()
{   
    uart_config_t uart_config = {
        .baud_rate = 115200,
        .data_bits = UART_DATA_8_BITS,
        .parity    = UART_PARITY_DISABLE,
        .stop_bits = UART_STOP_BITS_1,
        .flow_ctrl = UART_HW_FLOWCTRL_DISABLE,
        .source_clk = UART_SCLK_DEFAULT,
    };


    SMILE_UART_NUM = UART_NUM_0;  // *** CHANGED FOR UART0
    esp_err_t r;
    const int uart_buffer_size = (1024 * 2);
    QueueHandle_t uart_queue;

    r = uart_driver_install(SMILE_UART_NUM, uart_buffer_size, uart_buffer_size, 10, NULL, 0);
    r = uart_param_config(SMILE_UART_NUM, &uart_config);
    r = uart_set_pin(SMILE_UART_NUM, UART_PIN_NO_CHANGE,UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE);    // *** CHANGED FOR UART0
}

It does not work. I can send data out of UART0, but data I sent into UART0 is not received. The only thing different is the UART_NUM and the fact that I'm leaving the pins to the default values (as you can see on the pinout, the UART0 is dedicated to pins GPIO16 and 17), and I'm connecting to the appropriate pins.

Why would UART1 work on RX, but not RX over UART0, using near-identical code and connecting to the specified pins?

Thanks for any insight... reaching my wits end on this one.

0

There are 0 best solutions below