Page 1 of 1

unable to use uart1 and uart2 simultaneously

Posted: Tue Jul 20, 2021 9:12 am
by ht_main1
Hi
I am trying to use 2 uart in the same project this is the first time using 2 uarts of ESP32.
i have tried combination of UART0 & UART1 or UART1 & UART2, UART2 & UART0 but no result,
there is a problem when I try to use both UARt components, only one Uart transmit out.
i am unable to diagnose problem, kindly help me in the same

i am providing code snippet

Code: Untitled.c Select all



#define EX_UART_NUM UART_NUM_2
#define BUF_SIZE (1024)
#define RD_BUF_SIZE (BUF_SIZE)
static QueueHandle_t uart0_queue, uart1_queue;

/*-------main()---------*/

esp_log_level_set(TAG, ESP_LOG_INFO);
// Initialize NVS
esp_err_t ret = nvs_flash_init();
if (ret == ESP_ERR_NVS_NO_FREE_PAGES || ret == ESP_ERR_NVS_NEW_VERSION_FOUND) {
ESP_ERROR_CHECK(nvs_flash_erase());
ret = nvs_flash_init();
}
ESP_ERROR_CHECK( ret );

wifi_scan();

/* Configure parameters of an UART driver,
* communication pins and install the driver */
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
};
uart_param_config(EX_UART_NUM, &uart_config);

//Set UART 2 pins (using UART0 default pins ie no changes.)
//-------------------------tx--rx
uart_set_pin(EX_UART_NUM, 26, 25, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE);

//Install UART driver, and get the queue.
uart_driver_install(EX_UART_NUM, BUF_SIZE * 2, BUF_SIZE * 2, 20, &uart0_queue, 0);

// set UART 0

uart_param_config(0, &uart_config);

uart_set_pin(0, 4, 5, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE);

uart_driver_install(0, BUF_SIZE * 2, BUF_SIZE * 2, 20, &uart1_queue, 0);