UART Echo example in ESP IDF 4.0.1 with UART 1

Kampino
Posts: 7
Joined: Fri Jan 08, 2021 12:19 pm

UART Echo example in ESP IDF 4.0.1 with UART 1

Postby Kampino » Sun Feb 06, 2022 5:14 pm

Hello,

I use the UART Echo example with ESP IDF 4.0.1 and it looks like the software isn´t receiving anything when I use UART 1.

Code: Select all

#include <stdio.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "driver/uart.h"
#include "driver/gpio.h"
#include "sdkconfig.h"
#include "esp_log.h"

static const char *TAG = "UART TEST";

#define INTERFACE UART_NUM_1
#define BUF_SIZE (1024)

static void echo_task(void *arg)
{
    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
    };
    int intr_alloc_flags = 0;

#if CONFIG_UART_ISR_IN_IRAM
    intr_alloc_flags = ESP_INTR_FLAG_IRAM;
#endif

    ESP_ERROR_CHECK(uart_driver_install(INTERFACE, BUF_SIZE * 2, 0, 0, NULL, intr_alloc_flags));
    ESP_ERROR_CHECK(uart_param_config(INTERFACE, &uart_config));
    ESP_ERROR_CHECK(uart_set_pin(INTERFACE, 5, 18, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE));

    char Message[] = "AA";
    uint8_t *data = (uint8_t *) malloc(BUF_SIZE);

    while(1)
    {
        uart_write_bytes(INTERFACE, (const char*)Message, sizeof(Message));
        int len = uart_read_bytes(INTERFACE, data, (BUF_SIZE - 1), 20 / portTICK_RATE_MS);
        if(len)
        {
            data[len] = '\0';
            ESP_LOGI(TAG, "Recv str: %s", (char *) data);
        }

        vTaskDelay(1000 / portTICK_PERIOD_MS);
    }
}

extern "C" void app_main(void)
{
    xTaskCreate(echo_task, "uart_echo_task", 2048, NULL, 10, NULL);
}
I have bridged pin 5 and 18 and the example works like a charm when I use ESP IDF version 4.3.1. How can I use this example with IDF 4.0.1? What is the bug here?

Thank you for help.

Jeevan
Posts: 3
Joined: Thu Mar 17, 2022 4:58 pm

Re: UART Echo example in ESP IDF 4.0.1 with UART 1

Postby Jeevan » Tue Jul 19, 2022 11:07 am

May I ask how do you monitor the data sent by uart.
Also when writing to it, you use a serial monitor to e.g. Teraterm to write to the port connected to pons 5&18?

Who is online

Users browsing this forum: No registered users and 81 guests