Do I need to do something special to talk to dev kit UART0?

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

Do I need to do something special to talk to dev kit UART0?

Postby chris.f.rice » Thu Feb 01, 2024 8:24 pm

Hello, I'm trying to write some UART code to talk to my ESP32c6-DEVKITC1. I am able to read and write through UART1 through pins 10 and 11, with the first code snippet below. But I am not able to talk through UART0 through pins U0TXD/GPIO16, U0RXD/GPIO17, using the second code snippet below.

Is there something extra I need to do to take control of UART0, such as changing the pin functions? Or could this port have been commandeered by some ESP-IDF printf functionality, which I need to deactivate?

OR, do I have a simple bug in my code below?

Thanks very much for any help!

Code: Select all

const uart_port_t SMILE_UART_NUM = UART_NUM_1;

int UART_Initialize()
{
    esp_err_t r;

    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,
        .rx_flow_ctrl_thresh = 122,
    };    

    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); // worls with test loop
    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, &uart_queue, 0);

    printf("Successfully initialized UART\n");
    return 0;
}

void UART_SendChar(char c)
{
    esp_err_t r;
    char c2 = c;
    r = uart_write_bytes(SMILE_UART_NUM, &c2, 1);  
}


Code: Select all

const uart_port_t SMILE_UART_NUM = UART_NUM_0;   // **** CHANGED FROM 1 TO 0

int UART_Initialize()
{
    esp_err_t r;

    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,
        .rx_flow_ctrl_thresh = 122,
    };    

    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 TO DEFAULT PINS (U0TXD/GPIO16, U0RXD/GPIO17)
    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, &uart_queue, 0);

    printf("Successfully initialized UART\n");
    return 0;
}

void UART_SendChar(char c)
{
    esp_err_t r;
    char c2 = c;
    r = uart_write_bytes(SMILE_UART_NUM, &c2, 1);  
}


Who is online

Users browsing this forum: Bing [Bot] and 84 guests