uart_wait_tx_done() fails when sending a single byte

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

uart_wait_tx_done() fails when sending a single byte

Postby Jami17 » Sat Feb 03, 2018 11:11 am

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 ?

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

Re: uart_wait_tx_done() fails when sending a single byte

Postby WiFive » Mon Feb 05, 2018 2:29 pm

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

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

Re: uart_wait_tx_done() fails when sending a single byte

Postby Jami17 » Thu Feb 08, 2018 12:04 am

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

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

Re: uart_wait_tx_done() fails when sending a single byte

Postby WiFive » Thu Feb 08, 2018 12:23 am

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.

Who is online

Users browsing this forum: No registered users and 70 guests