imx UART how detect that THR and TSR are empty.

Discussion created by fear_nada on Nov 10, 2011
Latest reply on Feb 7, 2012 by Levente Tamas
I use the transceiver rs485 and UART, I control the direction of the transceiver via gpio, I need to determine when to switch it to the reception. I need to understand that the THR and TSR registers is empty, how it determined? imx UARTs not have any status bits for it or i miss it. Any help? i am trying like this: //==================================================== //wait until fifo emty while((HW_UARTAPPSTAT_RD(pHWHead->dwIndex) & BM_UARTAPPSTAT_TXFE)==0) Sleep(0); //   //Disable the TX interrupts HW_UARTAPPINTR_CLR(pHWHead->dwIndex, BM_UARTAPPINTR_TXIEN); //Clear INTS HW_UARTAPPINTR_CLR(pHWHead->dwIndex, BM_UARTAPPINTR_TXIS & ALL_INT_STATUS_MASK); //Sleep a bit for empty THR and TSR if we not sleep - RTS go to low too fast and our RS485 transiver cut last byte!  if ((pHWHead->dcb.BaudRate)<=7200) Sleep(10); //for 1200 bps need more time for Sleep else if ((pHWHead->dcb.BaudRate)<=38400) Sleep(2); //for medium speed sleep 2 ms else Sleep(1); //for hight speed sleep 1 ms //  //====================================================   but this is working only if OS not hardly loaded by processes. If we cpu are loaded we got answers from external device before turn on receiver.