Implementing single wire UART Comms

Go To Last Post
7 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I need to have a UART link with only a single wire. I have done the hardware side of it by connecting RXD to my line, and TXD via a diode, cathode to TXD. So TXD can pull the line low, and RXD always reads it. The other end of the line is connected to a similarly configured UART.

 

My question is what is the beast way of disabling the receive so that it does not see the locally transmitted character? I can think of several ways to do it, even just setting a flag when a char is transmitted, and when one is received ignoring it if the flag is set and then clearing the flag.

 

There must be a canonical way of doing this, I just can't find it.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Some microprocessors support a HALF-DUPLEX mode in their UART. Also used for ISO 7816 smart cards which use half-duplex asynchronous UARTs.  I suspect Atmel's low end Cortex ARMs have and maybe Xmega.

I use the STM32F4xx ARMs that have several such UARTs.

Essentially, in half duplex mode, the UART RX is connected to the TX internally. The UART is told to use half duplex mode. You cannot receive and transmit simultaneously. In the smart card case, the UART must use 8 data bits plus a 9th bit for parity.

 

In a non-half-duplex type of UART, one can transmit, wait until the last-transmitted byte has left the 2nd rank parallel-to-serial shift register, including the 1 or 2 stop bits, then use the RX function. The trick is that a UART status bit other than TX Register Empty is needed- as that's rank 1, not rank 2. Another way is to merely add a 1.5 character time delay after TX empty goes true, before using the RX side.

 

In many systems, there's a guard time of 2 bits or more for the turn-around time from TX to RX, for every node. In this guard time, the receiving UART is permitted, by ISO standards to pull the TX/RX line low during the stop bits, to signal there's been a parity error.

 

Another way is to choose an MCU with a CAN bus interface. It has a way to do bus arbitration.

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Sounds just like rs485 without the differential driver. tx enabled, rx disabled, send the packet, when TXComplete bit sets, go back into rx enabled tx disabled. I think.

 

Imagecraft compiler user

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I forgot to add that I don't need performance in this application, so I could just turn off the receiver when I transmit a character, then turn it back on when the TXC bit sets again.  The question remains of _how_ to disable the receiver. Can I just turn off the RXEN bit in UCSRB (I'm using the ATMega16)? I've never played with this bit beyond turning on the RX & TX together when initialising the UART.

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

you can't turn off the receiver in this kind of UART.

TXC true is not enough. You need to know when, or delay until, the last STOP bit of the last char in the structured message has been sent and it's time to turn the line and receive. A delay will do.

After the last stop bit, you can clear any received chars, clear error bits, and receive again.
 

Last Edited: Mon. Feb 2, 2015 - 01:36 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

celephicus2 wrote:

My question is what is the beast way of disabling the receive so that it does not see the locally transmitted character? I can think of several ways to do it, even just setting a flag when a char is transmitted, and when one is received ignoring it if the flag is set and then clearing the flag.

Because the TX and RX have slight phase shifts in their state engines, and you know to always expect an echo-Rx, the Flag is the simplest.

On every RX, wait for both TX Done and RX, if the TX_Flag is set, compare RX=TX if you want to catch contention.

After the last RX in, change the flag, but do not mess with the RX state engine. No need to Start/stop.

 

The remote will reply with varying delays, remembering its TX clock will not be locked to the master, so you need to check if a really fast echo of the right (wrong?) phase can eat into the STOP bit, which cuts margins for Monitoring terminals etc.

Some small turn-around delay (1+ bit times) would ensure no sub-baud effects.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Why disable the RX, use it to verify the TX was sent without a collision with another MCU trying to TX at the same time.  Also you can use the RXC flag to know when the TX char has completed shifting out of its register.   

 

 

Jim

 

 

Click Link: Get Free Stock: Retire early! PM for strategy

share.robinhood.com/jamesc3274
get $5 free gold/silver https://www.onegold.com/join/713...