Can receive characters via UART1, but not UART0

chris.f.rice
Posts: 7
Joined: Tue Jan 23, 2024 4:50 pm

Can receive characters via UART1, but not UART0

Postby chris.f.rice » Wed Feb 07, 2024 2:20 pm

UPDATE: this is happening on two different boards, and I don't seem to be able to find ANY example code that sets up UART0 for receiving. This is getting absurd, the most basic function on a controller and I can't get it to work. Does anyone have any theories, or a pointer to some code that should receive chars over UART0??

Is this console subsystem somehow setup by default to prevent this???

https://docs.espressif.com/projects/esp ... nsole.html

Thanks for any help, this is extremely frustrating.

***

I asked a version of this question earlier, but didn't get any replies. Usually that means that my question wasn't asked well, or the code *should* work and the problem is something else. I'll ask again in case I asked it poorly.

I am using 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/esp ... layout.png

I'm able to both send and received over UART1 using this code:

Code: Select all

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:

Code: Select all

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.

UPDATE: By the way, if you looked at this post (thank you), checked out the code and do NOT see a problem, if it SHOULD work, that would be helpful to know too...

chegewara
Posts: 2362
Joined: Wed Jun 14, 2017 9:00 pm

Re: Can receive characters via UART1, but not UART0

Postby chegewara » Tue Feb 13, 2024 2:24 am

Do you want to use native pins for UART0? (pin 2 and 3)

Code: Select all

uart_set_pin(SMILE_UART_NUM, UART_PIN_NO_CHANGE,UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE);
For UART1 you are using pin 10 and 11.

https://espressif-docs.readthedocs-host ... de.html#j3

User avatar
ok-home
Posts: 78
Joined: Sun May 02, 2021 7:23 pm
Location: Russia Novosibirsk
Contact:

Re: Can receive characters via UART1, but not UART0

Postby ok-home » Tue Feb 13, 2024 6:12 am

Hi
You are using the default gpio.
on the devkit gpio rxd0 is connected to the output of usb-rs232 converter.
if you signal rxd0 - the chip input will be something incomprehensible, either 1 or 0 or 0,5 - depending on who has a more powerful output in this case you need to change the assignment of gpio

chris.f.rice
Posts: 7
Joined: Tue Jan 23, 2024 4:50 pm

Re: Can receive characters via UART1, but not UART0

Postby chris.f.rice » Sun Feb 18, 2024 3:11 pm

Thank you ok-home, you are right that was the problem. Not sure why the dev kit would come shipped with this problem...

Who is online

Users browsing this forum: No registered users and 91 guests