dynamically switch UART IO Pins #11581
Unanswered
giancarlo64
asked this question in
ESP32
Replies: 1 comment 3 replies
-
You could try clearing the buffer with a uart.read() before the uart.write() |
Beta Was this translation helpful? Give feedback.
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi,
I have a serial device connected trough UART with my ESP32. Only during communication I can keep the RS232 connected. In the rest of the time the connection must be on high impedance (Tristate) (like no connection on the Tx Pin).
So I need to switch dynamically the UART Tx Pin from OUT to High impedance and back.
I have tried the following code :
#enable UART
uart1 = UART(1, baudrate=115200, tx=3, rx=4, bits=8, stop=1)
uart.write('rdstat\r')
sleep(1.5)
data = uart.read()
size=len(data)
data = data[:size - 2]
rx_bytearray=ubinascii.unhexlify(data)
other code
......
.......
#disable TX PIN
p3=Pin(3,Pin.IN)
sleep(1.5)
#enable UART
uart1 = UART(1, baudrate=115200, tx=3, rx=4, bits=8, stop=1)
sleep(2) # wait to settle
uart.write('rdstat\r')
sleep(1.5)
data = uart.read()
size=len(data)
data = data[:size - 2]
rx_bytearray=ubinascii.unhexlify(data)
after I get the following error
ValueError: odd-length string or ValueError: non-hex digit found
If I don't switch off pin 3 I get no errors
How can I put the TX of the UART in Tristate mode when not used?
Regards
Gian Carlo
Beta Was this translation helpful? Give feedback.
All reactions