Using all three UARTS for module communication

thanlong341
Posts: 5
Joined: Thu Jan 09, 2020 4:05 pm

Using all three UARTS for module communication

Postby thanlong341 » Thu Feb 06, 2020 2:16 pm

Hello all,

I am working with a project using ESP32 to communicate with 3 modules using UART, I use UART1 and UART2 for LoRa and Sigfox modules which work perfectly find. Then, I decided to use ft2232h mini module as an external debugger for ESP32 in order to use UART0 for a GPS module. However, there is no communication at all in the UART0, in the console, I can see that it tries to print something, but all I can see is blank spaces. But when I connect the GPS with other UART, it works fine. Please help me do the configuration to use all three UARTs. Below is my code, which is taken from ESP IDF UART example. Thank you.
https://github.com/espressif/esp-idf/tr ... 183_parser.

Code: Select all

/* NMEA Parser example, that decode data stream from GPS receiver

   This example code is in the Public Domain (or CC0 licensed, at your option.)

   Unless required by applicable law or agreed to in writing, this
   software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
   CONDITIONS OF ANY KIND, either express or implied.
*/

#include <stdio.h>
#include <stdlib.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "esp_log.h"
#include "nmea_parser.h"

static const char *TAG = "gps_demo";

#define TIME_ZONE (+1)   //Paris Time
#define YEAR_BASE (2000) //date in GPS starts from 2000

/**
 * @brief GPS Event Handler
 *
 * @param event_handler_arg handler specific arguments
 * @param event_base event base, here is fixed to ESP_NMEA_EVENT
 * @param event_id event id
 * @param event_data event specific arguments
 */
static void gps_event_handler(void *event_handler_arg, esp_event_base_t event_base, int32_t event_id, void *event_data)
{
    gps_t *gps = NULL;
    switch (event_id) {
    case GPS_UPDATE:
        gps = (gps_t *)event_data;
        /* print information parsed from GPS statements */
        ESP_LOGI(TAG, "%d/%d/%d %d:%d:%d => \r\n"
                 "\t\t\t\t\t\tlatitude   = %.05f°N\r\n"
                 "\t\t\t\t\t\tlongtitude = %.05f°E\r\n"
                 "\t\t\t\t\t\taltitude   = %.02fm\r\n"
                 "\t\t\t\t\t\tspeed      = %fm/s",
                 gps->date.year + YEAR_BASE, gps->date.month, gps->date.day,
                 gps->tim.hour + TIME_ZONE, gps->tim.minute, gps->tim.second,
                 gps->latitude, gps->longitude, gps->altitude, gps->speed);
        break;
    case GPS_UNKNOWN:
        /* print unknown statements */
        ESP_LOGW(TAG, "Unknown statement:%s", (char *)event_data);
        break;
    default:
        break;
    }
}

void app_main()
{
    /* NMEA parser configuration */
    // nmea_parser_config_t config = NMEA_PARSER_CONFIG_DEFAULT();
    nmea_parser_config_t config = {                                      \
        .uart = {                          \
            .uart_port = UART_NUM_0,       \
            .rx_pin = 3,                   \
            .baud_rate = 9600,             \
            .data_bits = UART_DATA_8_BITS, \
            .parity = UART_PARITY_DISABLE, \
            .stop_bits = UART_STOP_BITS_1, \
            .event_queue_size = 16         \
        }                                  \
    };
    /* init NMEA parser library */
    nmea_parser_handle_t nmea_hdl = nmea_parser_init(&config);
    /* register event handler for NMEA parser library */
    nmea_parser_add_handler(nmea_hdl, gps_event_handler, NULL);

    vTaskDelay(10000 / portTICK_PERIOD_MS);

    /* unregister event handler */
    nmea_parser_remove_handler(nmea_hdl, gps_event_handler);
    /* deinit NMEA parser library */
    nmea_parser_deinit(nmea_hdl);
}

username
Posts: 542
Joined: Thu May 03, 2018 1:18 pm

Re: Using all three UARTS for module communication

Postby username » Thu Feb 06, 2020 4:59 pm

Are you using an ESP32 Module of some sort? If so, it already has a USB - Serial interface connected to UART0. So you will not be able to use UART0 RX line unless you cut the RX trace from it to the ESP32 module.

WiFive
Posts: 3529
Joined: Tue Dec 01, 2015 7:35 am

Re: Using all three UARTS for module communication

Postby WiFive » Fri Feb 07, 2020 12:01 am

username wrote:
Thu Feb 06, 2020 4:59 pm
Are you using an ESP32 Module of some sort? If so, it already has a USB - Serial interface connected to UART0. So you will not be able to use UART0 RX line unless you cut the RX trace from it to the ESP32 module.
No you can just initialize it on different pins

thanlong341
Posts: 5
Joined: Thu Jan 09, 2020 4:05 pm

Re: Using all three UARTS for module communication

Postby thanlong341 » Fri Feb 07, 2020 7:21 am

I am using the ESP32-WROOM-32 module, before I also checked with the ESP32 devkit, but I will try to change the UART0 to other pins and update the result here, thank you guys

thanlong341
Posts: 5
Joined: Thu Jan 09, 2020 4:05 pm

Re: Using all three UARTS for module communication

Postby thanlong341 » Thu Feb 13, 2020 9:51 am

Hello all,

I have tried to change the rx pin and tx pin of UART0 and flash the program, however, the MCU doesn't run at all. the Log run until this point and stops:

Code: Select all

I (71) boot: Chip Revision: 1
I (71) boot_comm: chip revision: 1, min. bootloader chip revision: 0
I (41) boot: ESP-IDF v4.0-beta2-368-g463a9d8b7-dirty 2nd stage bootloader
I (41) boot: compile time 13:52:42
I (42) boot: Enabling RNG early entropy source...
I (48) boot: SPI Speed      : 40MHz
I (52) boot: SPI Mode       : DIO
I (56) boot: SPI Flash Size : 2MB
I (60) boot: Partition Table:
I (63) boot: ## Label            Usage          Type ST Offset   Length
I (71) boot:  0 nvs              WiFi data        01 02 00009000 00006000
I (78) boot:  1 phy_init         RF data          01 01 0000f000 00001000
I (86) boot:  2 factory          factory app      00 00 00010000 00100000
I (93) boot: End of partition table
I (97) boot_comm: chip revision: 1, min. application chip revision: 0
I (104) esp_image: segment 0: paddr=0x00010020 vaddr=0x3f400020 size=0x06ea4 ( 28324) map
I (124) esp_image: segment 1: paddr=0x00016ecc vaddr=0x3ffb0000 size=0x020e0 (  8416) load
I (127) esp_image: segment 2: paddr=0x00018fb4 vaddr=0x40080000 size=0x00400 (  1024) load
0x40080000: _WindowOverflow4 at C:/esp/esp-idf/components/freertos/xtensa_vectors.S:1778

I (132) esp_image: segment 3: paddr=0x000193bc vaddr=0x40080400 size=0x06c54 ( 27732) load
I (152) esp_image: segment 4: paddr=0x00020018 vaddr=0x400d0018 size=0x17a38 ( 96824) map
0x400d0018: _stext at ??:?

I (187) esp_image: segment 5: paddr=0x00037a58 vaddr=0x40087054 size=0x03784 ( 14212) load
0x40087054: rtc_clk_cal_internal at C:/esp/esp-idf/components/soc/esp32/rtc_time.c:99

I (200) boot: Loaded app from partition at offset 0x10000
I (200) boot: Disabling RNG early entropy source...
I (200) cpu_start: Pro cpu up.
I (204) cpu_start: Application information:
I (209) cpu_start: Project name:     nmea_parser
I (214) cpu_start: App version:      1
I (218) cpu_start: Compile time:     Feb  6 2020 13:52:07
I (224) cpu_start: ELF file SHA256:  5347018efac14671...
I (230) cpu_start: ESP-IDF:          v4.0-beta2-368-g463a9d8b7-dirty
I (237) cpu_start: Starting app cpu, entry point is 0x40081054
0x40081054: call_start_cpu1 at C:/esp/esp-idf/components/esp32/cpu_start.c:272

I (0) cpu_start: App cpu up.
I (248) heap_init: Initializing. RAM available for dynamic allocation:
I (255) heap_init: At 3FFAE6E0 len 00001920 (6 KiB): DRAM
I (261) heap_init: At 3FFB30D0 len 0002CF30 (179 KiB): DRAM
I (267) heap_init: At 3FFE0440 len 00003AE0 (14 KiB): D/IRAM
I (273) heap_init: At 3FFE4350 len 0001BCB0 (111 KiB): D/IRAM
I (280) heap_init: At 4008A7D8 len 00015828 (86 KiB): IRAM
I (286) cpu_start: Pro cpu start user code
I (304) spi_flash: detected chip: generic
I (305) spi_flash: flash io: dio
W (305) spi_flash: Detected size(4096k) larger than the size in the binary image header(2048k). Using the size in the binary image header.
�
Done
Normally, I should see the line "Start task schedule..." at the end of the log. below is my code so far. I use debugger to check the value of GPS, because for sure I cannot use UART0 for debugging log.

Code: Select all

/* NMEA Parser example, that decode data stream from GPS receiver

   This example code is in the Public Domain (or CC0 licensed, at your option.)

   Unless required by applicable law or agreed to in writing, this
   software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
   CONDITIONS OF ANY KIND, either express or implied.
*/

#include <stdio.h>
#include <stdlib.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "esp_log.h"
#include "nmea_parser.h"
#include "driver/gpio.h"
#include "string.h"


static const char *TAG = "gps_demo";

#define TIME_ZONE (+1)   //Paris Time
#define YEAR_BASE (2000) //date in GPS starts from 2000

gps_t *gps = NULL;

int a = 0;


/**
 * @brief GPS Event Handler
 *
 * @param event_handler_arg handler specific arguments
 * @param event_base event base, here is fixed to ESP_NMEA_EVENT
 * @param event_id event id
 * @param event_data event specific arguments
 */
static void gps_event_handler(void *event_handler_arg, esp_event_base_t event_base, int32_t event_id, void *event_data)
{
    // gps_t *gps = NULL;
    // switch (event_id) {
    // case GPS_UPDATE:
        gps = (gps_t *)event_data;
        /* print information parsed from GPS statements */
        // ESP_LOGI(TAG, "%d/%d/%d %d:%d:%d => \r\n"
        //          "\t\t\t\t\t\tlatitude   = %.05f°N\r\n"
        //          "\t\t\t\t\t\tlongtitude = %.05f°E\r\n"
        //          "\t\t\t\t\t\taltitude   = %.02fm\r\n"
        //          "\t\t\t\t\t\tspeed      = %fm/s",
        //          gps->date.year + YEAR_BASE, gps->date.month, gps->date.day,
        //          gps->tim.hour + TIME_ZONE, gps->tim.minute, gps->tim.second,
        //          gps->latitude, gps->longitude, gps->altitude, gps->speed);
        // break;
    // case GPS_UNKNOWN:
        /* print unknown statements */
        // ESP_LOGW(TAG, "Unknown statement:%s", (char *)event_data);
    //     break;
    // default:
    //     break;
    // }
}

void app_main()
{
    init_u2_sig();
    // gpio_gps_init();
    // gpio_set_level(GPS_EN_PIN, 0);
    // printf("%d\n", GPS_EN_PIN);
    /* NMEA parser configuration */
    // nmea_parser_config_t config = NMEA_PARSER_CONFIG_DEFAULT();
    nmea_parser_config_t config = {                                      \
        .uart = {                          \
            .uart_port = UART_NUM_0,       \
            .rx_pin = 2,                   \
            .baud_rate = 9600,             \
            .data_bits = UART_DATA_8_BITS, \
            .parity = UART_PARITY_DISABLE, \
            .stop_bits = UART_STOP_BITS_1, \
            .event_queue_size = 16         \
        }                                  \
    };
    /* init NMEA parser library */
    nmea_parser_handle_t nmea_hdl = nmea_parser_init(&config);
    /* register event handler for NMEA parser library */
    while (1)
    {
        nmea_parser_add_handler(nmea_hdl, gps_event_handler, NULL);
        
        // nmea_parser_add_handler(nmea_hdl, gps_event_handler, NULL);
        /* unregister event handler */
        nmea_parser_remove_handler(nmea_hdl, gps_event_handler);
        /* deinit NMEA parser library */
        nmea_parser_deinit(nmea_hdl);
        vTaskDelay(5000 / portTICK_PERIOD_MS);
    }
    // nmea_parser_add_handler(nmea_hdl, gps_event_handler, NULL);

    vTaskDelay(10000 / portTICK_PERIOD_MS);

    /* unregister event handler */
    nmea_parser_remove_handler(nmea_hdl, gps_event_handler);
    /* deinit NMEA parser library */
    nmea_parser_deinit(nmea_hdl);
    // int a = (int)gps->latitude;
    // char* pp = (char *)a;
    // uart_write_bytes(SF_UPORT, pp, strlen(pp)+1);
}

Please help me solve this problem :(

Thank you.

Palonso
Posts: 95
Joined: Tue Sep 24, 2019 8:43 pm

Re: Using all three UARTS for module communication

Postby Palonso » Mon May 18, 2020 10:14 pm

Were you able to find a solution to that?

I'm also looking a way to use the three UART buses of the ESP32 WROVER, but I want to disable the logging from the UART0 (the USB port by default) and use that bus to connect to another device.

Also I'm not looking to change the default pins, since I'm using a custom PCB with the WROVER module on it.

Techist
Posts: 2
Joined: Thu Jun 27, 2024 1:50 am

Re: Using all three UARTS for module communication

Postby Techist » Thu Jun 27, 2024 11:26 am

Hello, were you guys able to solve this?

I'm also trying to use the 3 UARTS on the ESP32­WROOM­ D. I can't find tangible information online.

Who is online

Users browsing this forum: Baidu [Spider] and 73 guests