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.
Thank you for your explain.
Actually, I use UART interface to send / receive RS485 data.
Because RS485 is working in half duplex transceiver mode. I need to know UART is complete send all data and switch to receive mode, so Nordic can receive data from RS485 mode.
Would you please tell me how can I do this job?
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 ...
Yes, you do.
If you look at the implementation in the library (app_uart_fifo.c), you can see that the whenever a NRF_DRV_UART_EVT_TX_DONE event is received from the driver (indicating that a byte have been successfully transmitted) it will pull a new byte from the FIFO and transmit this, or send the APP_UART_TX_EMPTY event if no more bytes are present in the FIFO:
// Get next byte from FIFO.
if (app_fifo_get(&m_tx_fifo, tx_buffer) == NRF_SUCCESS)
(void)nrf_drv_uart_tx(&app_uart_inst, tx_buffer, 1);
// Last byte from FIFO transmitted, notify the application.
app_uart_event.evt_type = APP_UART_TX_EMPTY;