Page 1 of 1
uart_wait_tx_done() fails when sending a single byte
Posted: Sat Feb 03, 2018 11:11 am
by Jami17
uart_wait_tx_done() is supposed to return when the last bit of a byte has been shifted out of the UART.
That indeed works nicely if more than 1 bytes are sent with uart_write_bytes().
But when sending a single byte then uart_wait_tx_done() returns immediately. So switching a RS485 driver is impossible.
Is this a UART h/w issue or can it be fixed in the driver s/w ?
Re: uart_wait_tx_done() fails when sending a single byte
Posted: Mon Feb 05, 2018 2:29 pm
by WiFive
You could try
Code: Select all
if(UART[uart_num]->status.txfifo_cnt == 0 && UART[uart_num]->status.st_utx_out == 0) {
https://github.com/espressif/esp-idf/bl ... art.c#L951
Re: uart_wait_tx_done() fails when sending a single byte
Posted: Thu Feb 08, 2018 12:04 am
by Jami17
Thanks!
That looks good. In a simple test it indeed worked. But when using it in a real protocol environment (when rcv is also involved) it behaved as before. For some reason it seems that status.st_utx_out was still set. Can it be cleared when calling uart_write_bytes() is called?
Or is it strictly h/w controlled?
Can it be done with this:
UART[uart_num]->status.st_utx_out = 0
Re: uart_wait_tx_done() fails when sending a single byte
Posted: Thu Feb 08, 2018 12:23 am
by WiFive
No it is hw controlled. That code path is to check if tx is already done. The idea was if the fifo is empty but the last byte is still being shifted out it would wait for the tx done interrupt. I am not sure of exactly when the fifo count goes to zero.