Synchronizing GPIO with UART state.

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

Synchronizing GPIO with UART state.

298 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by nakedible on Sat Nov 16 14:34:55 MST 2013
Hello,

I have a half-duplex RS-485 transceiver that has a separate "tx enable" line that I need to control. I need to turn "tx enable" on before the first start bit of a message, and turn it off after the last stop bit of a message. My solution to this was to turn the GPIO on when TXRDY was set in UART state flags, and turn it off after disabling the transmitter when TXDISINT flag was sent.

However, it seems that TXRDY is set *after* the start bit has already been sent, so this is too late. I tried setting the GPIO when enabling the transmit, but that meant that the transmit was enabled around 200 microseconds too early, two bits at 9600. Is there any way to get an interrupt or poll something that would let me know exactly when the start bit is being sent?

The same kind of problem exists for TXDISINT. This flag is set after the last data bit has been sent, but the stop bit is yet to be sent. If I turn the transmitter off at this point, the stop bit will not be transmitted on the wire. Is there any way to get an interrupt or poll something that would let me know exactly when the stop bit has been sent?

I can work around both of these issues somewhat with timers, but that would seem exceedingly ugly. At the moment, I am simply considering switching processors :-(
Labels (1)
0 Kudos
2 Replies

267 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by nakedible on Sun Nov 17 23:15:53 MST 2013
Turning on the RS485 driver just before putting data into the register causes the driver to be on for about 1.5 bits before transmitting the start bit. This means I am transmitting zero on the line before the start bit. This probably does not cause the equipment on the other end to act wrong, but still is not what I would like.

I think I tested that TXIDLE is also true before the stop bit has been sent, but I cannot be certain - I should retest. However, if it comes to polling, I'd rather do it with a timer, since the length of the stop bit does not need to be exact.
0 Kudos

267 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by noahk on Sun Nov 17 19:49:07 MST 2013
Hi nakedible,

Have you tried turning on the RS485 driver just before putting data into the transmit register? And turn it off after the TXIDLE bit goes high? You will have to poll TXIDLE, but you could use TXDISINT to get close to TXIDLE, and then poll the rest of the way. You'd probably want to wait for TXRDY (to be sure the holding register is empty), and then TXDISINT (to almost complete the transfer), and then poll for TXIDLE.

Let me know if that works out.

Noah
0 Kudos