uart_wait_tx_done() returns without waiting

Jami17
Posts: 14
Joined: Wed Jul 12, 2017 10:55 pm

uart_wait_tx_done() returns without waiting

Postby Jami17 » Thu May 09, 2019 12:38 pm

uart_wait_tx_done() does not wait but returns immediately under certain conditions.
It works when using it in another task, but fails when using it in the same thread that received a uart-message and then sends a uart-reply (15 bytes)

For a halfduplex RS485 I use this:
TX_ENABLE;
uart_write_bytes()
uart_wait_tx_done()
RX_ENABLE;

Result: the line is already set back to RX even before the first bit gets sent.

It works when adding a 150us delay
TX_ENABLE;
uart_write_bytes()
delayUs(150); // extra delay
uart_wait_tx_done()
RX_ENABLE;


I am using: ESP-IDF v3.3-beta2-18-g0f927791b-dirty

WiFive
Posts: 2472
Joined: Tue Dec 01, 2015 7:35 am

Re: uart_wait_tx_done() returns without waiting

Postby WiFive » Sun May 12, 2019 2:59 am

https://github.com/espressif/esp-idf/bl ... 1052-L1055

Maybe if the fifo hasn't been filled yet from the ringbuffer because of interrupt latency on the other core it will return immediately. So checking the fifo_cnt is not sufficient to determine whether the transmission is already done. The workaround would be only call uart_wait_tx_done on the core the interrupt runs on.

Jami17
Posts: 14
Joined: Wed Jul 12, 2017 10:55 pm

Re: uart_wait_tx_done() returns without waiting

Postby Jami17 » Mon May 13, 2019 9:13 pm

I suspected the same. However I don't like the suggested workaround, too complicated. It would be wise that uart_write_bytes() sets a flag that only gets cleared when the data is moved to the ringbuffer. So wait_tx_done() waits also while that flag is set. For now the delayUs() works fine for me.

Who is online

Users browsing this forum: No registered users and 3 guests