esp8266: Necessity for UART flush
This is rather recommendation than issue. The code below sends a string message from UART1 and is supposed to pull the output pin LOW :
mypin.on()
uart1.write("a long sentence")
mypin.off()
when I checked the signal (part tx and output) with logic analyzer, I saw that pin is pulled low long before the uart transmission has been completed. A function like uart.flash() which checks the relevant uart status bits for completion of the transmission would be very handy.
machine_uart: Implement a uart.flush() method,
uart.flush waits until data, which has been transferred has been sent. Regularly, users ask in the forum for a function like this. API:
rc = uart.flush([timeout])
rc is True, if all data has been sent within the timeout period, false otherwise. The default value for timeout is 1 hour (just a long time). Using a timeout value of 0 the method can be used to test, whether a transfer is ongoing. Supported ports:
- rp2: For messages shorter than 6 bytes, uart.flush() returns while the last byte is transferred.
- esp8266
- esp32
- stm32: for the stm32 port, uart.flush() is a dummy function which always returns True, because uart.write() itself does not return before all data has been sent.
- mimxrt
- nrf: For the nrf port uart.flush() is a dummy function as well, returning always True while the last byte is sent.
- cc3200
- samd: Implemented and kept in the 2nd level commit queue.