I use "printf" or "app_uart_put" function to print message to UART., how can I check "all of the data had been transmit out complete"?
When you call printf, all chars in the string will be put into the app_uart FIFO by multiple calls to app_uart_put(), and the library will start processing the FIFO. Then printf returns, all chars have been put into the FIFO. Whenever all bytes have been transmitted and the app_uart FIFO is empty, you will receive a APP_UART_TX_EMPTY event in the event handler. If you have added more bytes to the FIFO in the meantime, you will not receive an event until these bytes have been transmitted as well. There is no other functionality in the library to know when a transfer is completed.
Like I wrote in my previous answer, you will get a APP_UART_TX_EMPTY event when all bytes have been transmitted. You can set a flag in the event handler when you receive this event, and use this flag to no the switching between TX and RX.
Jørgen Holmefjord said:you will get a APP_UART_TX_EMPTY event when all bytes have been transmitted.
Or do you get that event when the last byte has been taken out of the FIFO, and loaded into the UART for transmission?
For turning round a half-duplex line (such as chianglin's RS485), you need to know the actual end of transmission - ie, when the final stop bit has left the shift register ...