configuring UART

User avatar
mzimmers
Posts: 643
Joined: Wed Mar 07, 2018 11:54 pm
Location: USA

configuring UART

Postby mzimmers » Wed Aug 01, 2018 8:17 pm

Hi -

I'm at a point in my project where I need to redirect my console/logging to a different UART than the default. I need to test the device running on battery power, and currently the only way to do this is to unplug the cable that provides serial communications as well as power. I tried just disconnecting the power line (leaving the others intact) but that didn't work, as evidently the UART derives its power from the cable.

Anyway, according to the WROOM datasheet, UART1 uses pins 17 and 18. I've tried to do some reading on this, but I can't find the answer: what do I need to do in order to configure these pins for this purpose?

Thanks...oh, and if anyone has a better idea for how to keep getting logs after I "pull the plug" then I'd love to hear them.

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

Re: configuring UART

Postby WiFive » Wed Aug 01, 2018 8:30 pm

If you have another usb-uart cable you should be able to attach it to the uart0 pins

mikemoy
Posts: 627
Joined: Fri Jan 12, 2018 9:10 pm

Re: configuring UART

Postby mikemoy » Wed Aug 01, 2018 9:07 pm

Haven't tried uart1 yet, but what I have been doing was to create a telnet server on it.

User avatar
mzimmers
Posts: 643
Joined: Wed Mar 07, 2018 11:54 pm
Location: USA

Re: configuring UART

Postby mzimmers » Wed Aug 01, 2018 9:17 pm

WiFive wrote:If you have another usb-uart cable you should be able to attach it to the uart0 pins
I'm not sure I understand you, but attaching another cable to UART0 won't help if the UART stops working when I disconnect the power line.

User avatar
mzimmers
Posts: 643
Joined: Wed Mar 07, 2018 11:54 pm
Location: USA

Re: configuring UART

Postby mzimmers » Thu Aug 02, 2018 3:21 pm

So, here's what I've done so far:

1. added a header that connects to pins 17 and 18 (per the manual).
2. Connected an FTDI cable to the header. Shows up as COM3.
3. changed make->menuconfig->ESP32-specific as follows:
- UART for console output: Custom
- UART peripheral to use for console output (0-1): UART1
- UART TX on GPIO#: 18
- UART RX on GPIO#: 17

I'm not seeing anything. Any idea what I might be doing wrong?

Thanks...

User avatar
mzimmers
Posts: 643
Joined: Wed Mar 07, 2018 11:54 pm
Location: USA

Re: configuring UART

Postby mzimmers » Thu Aug 02, 2018 6:17 pm

Hi Paul -

I'm afraid I don't understand. Yes, the device is connected to UART0, but why should that make working with UART1 difficult?

There exists an option in menuconfig to change where log messages are sent. I'd be happy if I could just get this working, but no luck so far.

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

Re: configuring UART

Postby WiFive » Thu Aug 02, 2018 6:25 pm

mzimmers wrote:
WiFive wrote:If you have another usb-uart cable you should be able to attach it to the uart0 pins
I'm not sure I understand you, but attaching another cable to UART0 won't help if the UART stops working when I disconnect the power line.
If the usb-uart chip on the board doesn't allow those pins to hi-z float when it is powered down then it could be a problem. The uart itself should still work fine.

linuxpaul
Posts: 43
Joined: Thu Jul 20, 2017 6:10 pm

Re: configuring UART

Postby linuxpaul » Thu Aug 02, 2018 7:02 pm

Hi,

sorry, I didn't get your demand correctly before, so I delete my post because the
answer doesn't help.

:)
linuxpaul

User avatar
mzimmers
Posts: 643
Joined: Wed Mar 07, 2018 11:54 pm
Location: USA

Re: configuring UART

Postby mzimmers » Thu Aug 02, 2018 7:43 pm

Hi Wifive -

I'd prefer to get UART1 working. I had initially assumed that merely making the changes in menuconfig would be adequate. But it occurred to me -- do I also need to set communications parameters/pins and install a driver for UART1?

User avatar
mzimmers
Posts: 643
Joined: Wed Mar 07, 2018 11:54 pm
Location: USA

Re: configuring UART

Postby mzimmers » Thu Aug 02, 2018 9:24 pm

So, I decided to ignore logging for now, and just concentrate on writing to UART1.

Here's my setup code:

Code: Select all

    uart_config_t uart_config;

    uart_config.baud_rate = 115200;
    uart_config.data_bits = UART_DATA_8_BITS;
    uart_config.parity = UART_PARITY_DISABLE;
    uart_config.stop_bits = UART_STOP_BITS_1;
    uart_config.flow_ctrl = UART_HW_FLOWCTRL_DISABLE;
    uart_config.rx_flow_ctrl_thresh = 122;
    uart_config.use_ref_tick = true;

    // load the configuration.
    err = uart_param_config(CD_UART_NBR, &uart_config);
    if (err == ESP_OK)
    {
        ESP_LOGI(TAG, "uart_param_config() successful.");
    }
    else
    {
        ESP_LOGE(TAG, "uart_param_config() returned %s.", esp_err_to_name(errno));
    }

    //Set UART pins.
    uart_set_pin(CD_UART_NBR,
                 18, // tx
                 17, // rx
                 UART_PIN_NO_CHANGE, // rts
                 UART_PIN_NO_CHANGE); //cts
    if (err == ESP_OK)
    {
        ESP_LOGI(TAG, "uart_set_pin() successful.");
    }
    else
    {
        ESP_LOGE(TAG, "uart_set_pin() returned %s.", esp_err_to_name(errno));
    }

    //Install UART driver, and get the queue.
    err = uart_driver_install(CD_UART_NBR, (BUF_SIZE * 2), (BUF_SIZE * 2), 20, &m_uartQueue, 0);
    if (err == ESP_OK)
    {
        ESP_LOGI(TAG, "uart_driver_install successful.");
    }
    else
    {
        ESP_LOGE(TAG, "uart_driver_install returned() %s.", esp_err_to_name(errno));
    }
}
And here's my write code:

Code: Select all

    char buff[] = "1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ";
    for (;;)
    {
        err = uart_write_bytes(UART_NUM_1, buff, strlen(buff));
        if (err >= 0)
        {
            ESP_LOGI(TAG, "uart_write_bytes wrote out %d bytes.", err);
        }
        else
        {
            ESP_LOGE(TAG, "uart_write_bytes returned %d.", err);
        }
        vTaskDelay(100);
    }
I get no error messages, but nothing is showing up in my PuTTY terminal that I have connected to UART1.

Can someone see something I'm doing wrong?

Thanks...

Who is online

Users browsing this forum: No registered users and 199 guests