I am trying to use GPIO 21 on ESP32 C3 for UART0 TX. I would like uses it with open drive feature.
I have tried with API and with register level instructions.
In API the instructions are the follow:
ESP_ERROR_CHECK(uart_param_config(S_BusPort, &uart_config_1));
ESP_ERROR_CHECK (uart_driver_install(S_BusPort, 1024, 1024, 0, NULL, 0));
……
ESP_ERROR_CHECK(uart_set_pin(S_BusPort, 21, 20, -1, -1));
……
ESP_ERROR_CHECK(gpio_set_direction (GPIO_NUM_21, GPIO_MODE_OUTPUT_OD));
ESP_ERROR_CHECK(gpio_pullup_en(GPIO_NUM_21));
The TX UART signal come out properly but not in open drain mode (both the rising and falling fronts are very steep).
Using register the instruction are the follow:
ESP_ERROR_CHECK(uart_param_config(S_BusPort, &uart_config_1));
ESP_ERROR_CHECK (uart_driver_install(S_BusPort, 1024, 1024, 0, NULL, 0));
……
REG_WRITE(GPIO_FUNC21_OUT_SEL_CFG_REG,0x006); //connect UART0 output signal to GPIO21
REG_WRITE(GPIO_PIN21_REG,0x04); //open drain activated
REG_WRITE(IO_MUX_GPIO21_REG,0x0900); //pull up activated
Also in this case the output UART signal come out properly but not in open drain mode.
Is there some thing wrong? Can someone help me? Or, simply, doesn’t ESP32 C3 support open drain mode when the GPIO is linked to the UART0 TX signal?
Thanks in advance.
Best regards,
Freddy_13
TX UART open drain mode
Re: TX UART open drain mode
Did you found a way to use od in uart tx?
In esp-idf 4.4 it works using:
But not in 5.2.
In esp-idf 4.4 it works using:
Code: Select all
gpio_set_direction(tx_io_num, GPIO_MODE_OUTPUT_OD)Re: TX UART open drain mode
I saw that new implementation connects gpio to gpio out signal when set direction.
I think one pad can be connected to only one signal. Then the serial signal are disconnected.
You can do an hack:
I think one pad can be connected to only one signal. Then the serial signal are disconnected.
Code: Select all
static esp_err_t gpio_output_enable(gpio_num_t gpio_num)
{
GPIO_CHECK(GPIO_IS_VALID_OUTPUT_GPIO(gpio_num), "GPIO output gpio_num error", ESP_ERR_INVALID_ARG);
gpio_hal_output_enable(gpio_context.gpio_hal, gpio_num);
esp_rom_gpio_connect_out_signal(gpio_num, SIG_GPIO_OUT_IDX, false, false);
return ESP_OK;
}Code: Select all
#include "hal/gpio_hal.h"
gpio_hal_context_t hal = {.dev = GPIO_HAL_GET_HW(GPIO_PORT_0)};
gpio_hal_od_enable(&hal, tx_io_num);
Re: TX UART open drain mode
I'm working on implementing half-duplex bidirectional UART communication on a single GPIO line with an original ESP32. Setup fixes for single-line UART have been published to the latest ESP-IDF...but they aren't present in ESP-IDF v5.1 (for Arduino-ESP32 v3.0.7). Independently found a similar solution to what you wrote above, also adding a weak pullup.Code: Select all
#include "hal/gpio_hal.h" gpio_hal_context_t hal = {.dev = GPIO_HAL_GET_HW(GPIO_PORT_0)}; gpio_hal_od_enable(&hal, tx_io_num);
Code: Select all
static gpio_hal_context_t _gpio_hal = {
.dev = GPIO_HAL_GET_HW(GPIO_PORT_0)
};
gpio_hal_od_enable(&_gpio_hal, pin);
gpio_pullup_en((gpio_num_t)pin);
Now to see if RX is actually on the same pin (as per the UART "setPins" request)...and if not, I'll have to backport the fixes with another hack. Fun times!
Who is online
Users browsing this forum: Applebot, Bing [Bot], Qwantbot, Semrush [Bot] and 15 guests