ESP32 WROVER UART problem

Viktrrrr
Posts: 3
Joined: Mon Jan 31, 2022 12:50 pm

ESP32 WROVER UART problem

Postby Viktrrrr » Mon Jan 31, 2022 1:02 pm

Hi there!

I have just a very little experience with ESP32 and its UART, tried it and ran into a problem. I want to test a KNX with ESP32, so I assembled a simple setup of 3 devices, made 2 NCN5120 devboards and tried to make ESP32 to communicate with KNX. But for some reason ESP reads a garbage. NCN is configured as 19200 8E1 and connected to GPIO 21/22 pins. Here's my MVE:

Code: Select all

{
    ets_printf("\nStarting\nSDK version %s\n", esp_get_idf_version());

    uart_config_t uartConfig = {
        .baud_rate = 19200,
        .data_bits = UART_DATA_8_BITS,
        .parity = UART_PARITY_EVEN,
        .stop_bits = UART_STOP_BITS_1,
        .flow_ctrl = UART_HW_FLOWCTRL_DISABLE,
        .rx_flow_ctrl_thresh = 122,// Tried also 0
        .source_clk = UART_SCLK_APB // Tried also UART_SCLK_REF_TICK
                      };

    int uartPortNumber = 1; // Tried also 2
    int pinTx = 21;
    int pinRx = 22;

    uart_driver_install(uartPortNumber, 1024, 0, 0, NULL, 0);
    uart_param_config(uartPortNumber, &uartConfig);
    uart_set_pin(uartPortNumber, pinTx, pinRx, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE);
    uart_set_baudrate(uartPortNumber, KNX_UART_SPEED);
    uart_set_word_length(uartPortNumber, UART_DATA_8_BITS);
    uart_set_parity(uartPortNumber, UART_PARITY_EVEN);
    uart_set_stop_bits(uartPortNumber, UART_STOP_BITS_1);
    uart_set_hw_flow_ctrl(uartPortNumber, UART_HW_FLOWCTRL_DISABLE, 0);
    uart_set_mode(uartPortNumber, UART_MODE_UART);

    uint8_t byte;

    byte = 1;
    if (uart_write_bytes(uartPortNumber, &byte, 1) != 1)
    {
        ets_printf("Init writte error\n");
    }
    else
    {
        ets_printf("init written ok\n");
    }
    if (uart_read_bytes(uartPortNumber, &byte, 1, 10000 / portTICK_RATE_MS) != 1 || byte != 3)
    {
        ets_printf("Init response read error\n");
    }
    else
    {
        ets_printf("init response read ok\n");
    }

    uint8_t address[4] = {0xf1, 0x41, 0x02, 0x00};
    if (uart_write_bytes(uartPortNumber, &address, 4) != 4)
    {
        ets_printf("Assign address writte error\n");
    }
    else
    {
        ets_printf("Assign address written ok\n");
    }
    if (uart_read_bytes(uartPortNumber, &byte, 1, 10000 / portTICK_RATE_MS) != 1 || byte != 0x21)
    {
        ets_printf("Assign address response  read error\n");
    }
    else
    {
        ets_printf("Assign address response read ok\n");
    }

    while (true)
    {

        int res;
        res = uart_read_bytes(uartPortNumber, (void *)&byte, 1, 10000 / portTICK_RATE_MS);

        if (res == 1)
        {
            ets_printf("%2.2X ", byte);
        }
        else
        {
            ets_printf("\n");
        }

        vTaskDelay(1);
    }
}
I did "read value" by ETS from one of the devices connected to the same bus. And here's its output:

Code: Select all

SDK version 4.3.2
init written ok
init response read ok
Assign address written ok
Assign address response read ok


47 BC 11 07 00 46 F5 54 14 B2 57
For testing I also make a simple MVE with Raspberry pi and Java/NRSerial and it works fine. Init:

Code: Select all

int baudRate = 19200;
NRSerialPort serial = new NRSerialPort(portName, baudRate);
serial.setDataBits(8);
serial.setParity(SerialPort.PARITY_EVEN);
serial.setStopBits(SerialPort.STOPBITS_1);
serial.connect();
The same frame readings (correct):

Code: Select all

Using port /dev/ttyAMA0
Sent reset, got response 0x03
Sent address, got response 0x21
BC 11 07 00 06 E1 00 00 B2
Probably I am doing something wrong when using ESP32's UART. Please advise how to do it correctly.
Thank you!

Viktrrrr
Posts: 3
Joined: Mon Jan 31, 2022 12:50 pm

Re: ESP32 WROVER UART problem

Postby Viktrrrr » Mon Jan 31, 2022 8:50 pm

Sorry guys, my mistake. I simply forgot to connect common ground wire rofl
🤣
sorry, now everything is working fine

Who is online

Users browsing this forum: MicroController and 151 guests