← index #8063Issue #8362
Related · high · value 0.461
QUERY · ISSUE

Esp32: Add explicit "wait_tx_done" method to UART

openby mrkeuzopened 2021-12-05updated 2022-05-27
port-esp32

Hello folks,

Faced with issue, I cannot control time when UART TX done from MicroPython.

Use case is next:

  • I've tried to communicate by raw RS485 and I should know when exactly disable TX pin.

Currently, there are couple workarounds (judged by sources and undocumented). In these methods called uart_wait_tx_done():

  • Via init() method. E.g. send bytes and call init(). But if implementation will be changed in future such method stopped worked. Especially this method is very strange to call in the middle of the UART operation.
  • Via sendbreak() method. But also undocumented plus it always sends \x00

Proposal:

  • I think it would be good to add explicit method for waiting UART TX done.
CANDIDATE · ISSUE

ESP32 / UART.deinit()

closedby cederomopened 2022-02-27updated 2024-09-08
proposed-close

Hello world :-)

I am using UART on ESP32 with MP 1.18. There is either bug in the documentation or ESP32 implementation of UART.deinit().

I cannot call UART.deinit() just do "turn off UART" to be used for later because it seems to destroy object that cannot be then initialised again.

The scenario is:

  • I have two UART based sensors. Both using different baudrate.
  • Device should be able to work with both sensors either-or-exclusively or both of them based on additional pin activation.
  • Both sensors can be attached to the same UART (only one sensor is active at time). They may also use different pins but the same UART (UART object may be reconfigured before read from each sensor).
  • I have created a driver that initializes the UART with UART.init() according to the sensor needs.
  • In order to conserve power each sensor is put to sleep by default, then wake up by pin and UART sequence, measurement is made, then sensor is put back to sleep with UART sequence and external pin.
  • When there is a UART.deinit() call put in sensor deactivation call, another init/read/write to the UART object is impossible.

According to UART documentation [1] UART.deinit() only "Turn off the UART bus." but there is no mention that object is destroyed and cannot be used again. I would like to init() and deinit() the same UART bus depending on which sensor is being used.

My questions:

  • Can I call UART.init() multiple times on the same object to change baudrate maybe even pins?
  • Can I call UART.deinit() before UART.init() is called again on the same object?

Depending on the above it seem that either or:

  • UART.deinit() destroys (not only turns off) the UART object so it cannot be used back again. The documentation needs to be updated in that case.
  • There is a bug in ESP32 implementation that prevents further UART.init() after UART.deinit().

[1] https://docs.micropython.org/en/latest/library/machine.UART.html?highlight=uart#machine.UART.deinit

Keyboard

j / / n
next pair
k / / p
previous pair
1 / / h
show query pane
2 / / l
show candidate pane
c
copy suggested comment
r
toggle reasoning
g i
go to index
?
show this help
esc
close overlays

press ? or esc to close

copied