How to "unset" pins assigned to a UART

MichaelS
Posts: 29
Joined: Mon Jul 08, 2024 12:08 am

How to "unset" pins assigned to a UART

Postby MichaelS » Sat Oct 26, 2024 5:52 am

Hi

I need to multiplex a serial port to drive 3 separate physical serial interfaces with separate baud rate setting etc. My application is the master and polls the 3 devices so can manage only talking to one device at a time.

I have plenty of GPIO spare so rather than add gate hardware to enable and disable 1 of the 3 multiplexed channels, I thought I could use uart_set_pin(...) to assign my UART to different sets of GPIO pins for Txd, Rxd and RTS (for RS-485 TxEnable). I don't use CTS so have left this set to -1

Code: Select all

    if (port == 0)
        ESP_ERROR_CHECK(uart_set_pin(uart_num, UARTMUX_1_TXD, UARTMUX_1_RXD, UARTMUX_1_RTS, UARTMUX_CTS));
    else if (port == 1)
        ESP_ERROR_CHECK(uart_set_pin(uart_num, UARTMUX_2_TXD, UARTMUX_2_RXD, UARTMUX_2_RTS, UARTMUX_CTS));
    else
        ESP_ERROR_CHECK(uart_set_pin(uart_num, UARTMUX_3_TXD, UARTMUX_3_RXD, UARTMUX_3_RTS, UARTMUX_CTS));
My code sort of works but I found (as documented) "Internal signal can be output to multiple GPIO pads"

So my UART Txd signals appear on all 3 UARTMUX_?_TXD pins at the same time, and same with RTS.

I tried calling uart_driver_delete() and uart_driver_install() between service each multiplexed channel but it didn't help.

I have come up with a "work around" which seems to work by setting the previous Txd GPIO line as an output level high after I have finished with it and the RTS GPIO line as an output level low after I have finished with it.

This works perfectly but feels like a bit of a hack. Is there a proper way to unassign GPIO pins from the UART to make this work more "correctly"?
Thanks

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

Re: How to "unset" pins assigned to a UART

Postby username » Sat Oct 26, 2024 2:46 pm

When your done using uart_set_pin(uart_num, UARTMUX_1_TXD, UARTMUX_1_RXD, UARTMUX_1_RTS, UARTMUX_CTS));

Have you tried:

gpio_reset_pin(UARTMUX_1_TXD);
gpio_reset_pin(UARTMUX_1_RXD);
gpio_reset_pin(UARTMUX_1_RTS);
gpio_reset_pin(UARTMUX_CTS);

MichaelS
Posts: 29
Joined: Mon Jul 08, 2024 12:08 am

Re: How to "unset" pins assigned to a UART

Postby MichaelS » Sun Oct 27, 2024 9:41 pm

Thank you. I searched the API spec back and forth but somehow completely missed this.

Who is online

Users browsing this forum: Bryght-Richard, ESP_Roland and 181 guests