How to "unset" pins assigned to a UART
Posted: 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
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
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));
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