imx UART how detect that THR and TSR are empty.

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

imx UART how detect that THR and TSR are empty.

2,005 Views
fear_nada
Contributor II
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.
Tags (1)
0 Kudos
8 Replies

1,121 Views
LeventeTamas
Contributor I

RTS pin direction depends on the selected UART mode. RTS is output in DTE mode and input in DCE mode. Very unfortunate naming;)

IMX53 Reference manual: 76.1.3 table 76-1.

0 Kudos

1,121 Views
fear_nada
Contributor II
I use RM for imx28. But RTS pin always output pin its 100%. try download from freescale site Reference Manual for imx53 and read about APPUART
0 Kudos

1,121 Views
Noel_V
Contributor III

Sorry, i'm here again.

What manual are you using ?

Finding the 'correct' manual seems to quite difficult

Regards,

Noel



Andrew I said:

RTS - its output pin =)

30.1 Application UART Overview
...
"The modem status input signal Clear To Send (CTS) and output modem control line Request
To Send (RTS) are supported."
...
0 Kudos

1,121 Views
Noel_V
Contributor III

Must be a fault (bug) into the iMX - processor reference manual  (as I expected !)

Thanks for the confirmation .



Andrew I said:

RTS - its output pin =)

30.1 Application UART Overview
...
"The modem status input signal Clear To Send (CTS) and output modem control line Request
To Send (RTS) are supported."
...
0 Kudos

1,121 Views
fear_nada
Contributor II
RTS - its output pin =) 30.1 Application UART Overview ... "The modem status input signal Clear To Send (CTS) and output modem control line Request To Send (RTS) are supported." ...
0 Kudos

1,121 Views
Noel_V
Contributor III

Hi Andrew,

First of all THANKS for the usefull-reply.


One more question on RTS, when I do read in the DATA-sheets I see that the RTS-pin is specified to be an INPUT, I would expect this to be an OUTPUT.


regards Noel


0 Kudos

1,121 Views
fear_nada
Contributor II
Hi i use RTS pin for this too. At first You can use HW_UARTAPP_STAT and check BUSY bit in SL_TxIntrHandler(). (The BUSY signal goes HIGH as soon as the data is written to the transmit FIFO (that is, the FIFO is non-empty) and remains asserted HIGH while data is being transmitted. BUSY is negated only when the transmit FIFO is empty, and the last character has been transmitted from the shift register, including the stop bits. BUSY can be asserted HIGH, even though the Application UART might no longer be enabled). like this //wait until fifo emty while((HW_UARTAPPSTAT_RD(pHWHead->dwIndex) & BM_UARTAPPSTAT_TXFE)==0) Sleep(0); // <<<<< EAI MAY BE HERE need remove Sleep and set just; //then FIFO all empty need poling BUSY flag antil TSR and THR not empty //CeSetThreadQuantum (CurHandle[pHWHead->dwIndex], 0); while((HW_UARTAPPSTAT_RD(pHWHead->dwIndex) & BM_UARTAPPSTAT_BUSY)!=0); // i AM use BUSY bit now!!! for TSR empty //manualy set RTS to 0 Volt for put in receive mode external transiver HW_UARTAPPCTRL2_CLR(pHWHead->dwIndex, BM_UARTAPPCTRL2_RTS); //CeSetThreadQuantum (CurHandle[pHWHead->dwIndex], 100); //100 ms this is default qauntum i have inverted RTS in Sl_INIT // if(pSerHead->RS485 == 1) { // HW_UARTAPPCTRL2_SET(pHWHead->dwIndex,BM_UARTAPPCTRL2_INVERT_RTS); // DEBUGMSG(1,(TEXT("_____SL_Reset pSerHead->RS485 == 1 \r\n"))); // } BUT! If you have very very fast answered slave device on rs485(answerede in 1-2 msec) you need put this code in OEMInterruptHandler () i do it by this : //eai addon // If IRQ_AUART1_TX_DMA interrupt if (irq == IRQ_AUART0_TX_DMA) { if(AUART0_LIKE_RS485==1) // set rts to 0 volt HW_UARTAPPCTRL2_CLR(pv_HWregUARTAPP0,BM_UARTAPPCTRL2_RTS); } else if (irq == IRQ_AUART1_TX_DMA) { if(AUART1_LIKE_RS485==1) // set rts to 0 volt HW_UARTAPPCTRL2_CLR(pv_HWregUARTAPP1,BM_UARTAPPCTRL2_RTS); } else if (irq == IRQ_AUART2_TX_DMA) { if(AUART2_LIKE_RS485==1) // set rts to 0 volt HW_UARTAPPCTRL2_CLR(pv_HWregUARTAPP2,BM_UARTAPPCTRL2_RTS); } else if (irq == IRQ_AUART3_TX_DMA) { if(AUART3_LIKE_RS485==1) // set rts to 0 volt HW_UARTAPPCTRL2_CLR(pv_HWregUARTAPP3,BM_UARTAPPCTRL2_RTS); } else if (irq == IRQ_AUART4_TX_DMA) { if(AUART4_LIKE_RS485==1) // set rts to 0 volt HW_UARTAPPCTRL2_CLR(pv_HWregUARTAPP4,BM_UARTAPPCTRL2_RTS); } //eai addon AUARTx_LIKE_RS485 - my globals for control=)
0 Kudos

1,121 Views
Noel_V
Contributor III

Hi,

I wonder if you have made any progress on this?

I would like to interface RS485 on the imx53.

In our older boards (none iMX) we use the RTS pin to controll the DRIVER_ENABLE.. would this still be possible ?

Regards Noel

0 Kudos