unable to use uart1 and uart2 simultaneously

ht_main1
Posts: 28
Joined: Sun Oct 06, 2019 6:08 pm

unable to use uart1 and uart2 simultaneously

Postby ht_main1 » Tue Jul 20, 2021 9:12 am

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
  1.  
  2. #define EX_UART_NUM UART_NUM_2
  3. #define BUF_SIZE (1024)
  4. #define RD_BUF_SIZE (BUF_SIZE)
  5. static QueueHandle_t uart0_queue, uart1_queue;
  6.  
  7. /*-------main()---------*/
  8.  
  9. esp_log_level_set(TAG, ESP_LOG_INFO);
  10.     // Initialize NVS
  11.     esp_err_t ret = nvs_flash_init();
  12.     if (ret == ESP_ERR_NVS_NO_FREE_PAGES || ret == ESP_ERR_NVS_NEW_VERSION_FOUND) {
  13.         ESP_ERROR_CHECK(nvs_flash_erase());
  14.         ret = nvs_flash_init();
  15.     }
  16.     ESP_ERROR_CHECK( ret );
  17.  
  18.     wifi_scan();
  19.  
  20.     /* Configure parameters of an UART driver,
  21.      * communication pins and install the driver */
  22.     uart_config_t uart_config = {
  23.         .baud_rate = 115200,
  24.         .data_bits = UART_DATA_8_BITS,
  25.         .parity = UART_PARITY_DISABLE,
  26.         .stop_bits = UART_STOP_BITS_1,
  27.         .flow_ctrl = UART_HW_FLOWCTRL_DISABLE
  28.     };
  29.     uart_param_config(EX_UART_NUM, &uart_config);
  30.  
  31.     //Set UART 2 pins (using UART0 default pins ie no changes.)
  32.     //-------------------------tx--rx
  33.     uart_set_pin(EX_UART_NUM, 26, 25, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE);
  34.  
  35.     //Install UART driver, and get the queue.
  36.     uart_driver_install(EX_UART_NUM, BUF_SIZE * 2, BUF_SIZE * 2, 20, &uart0_queue, 0);
  37.  
  38. // set UART 0
  39.  
  40.  uart_param_config(0, &uart_config);
  41.  
  42. uart_set_pin(0, 4, 5, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE);
  43.    
  44.     uart_driver_install(0, BUF_SIZE * 2, BUF_SIZE * 2, 20, &uart1_queue, 0);

Who is online

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