Single Wire Hardware Serial, Possible?

I'm using an SRF01 ranger for a project with a Mega 2560.
http://www.robot-electronics.co.uk/htm/srf01tech.htm
This device uses a single wire for bi-directional serial communication. The example uses a software serial port with both the TX and RX pins defined as the same pin and just changes the pinMode depending on whether you are sending or receiving. My understanding is software serial is limited to 9600 baud and is very time intensive.

Is there any way to utilize one of the additional hardware serial ports on the mega for single wire communication?

Thanks

http://arduino.cc/en/Reference/Serial/url]
The Arduino Mega has three additional serial ports: Serial1 on pins 19 (RX) and 18 (TX), Serial2 on pins 17 (RX) and 16 (TX), Serial3 on pins 15 (RX) and 14 (TX).

Also I believe in setup() you can

Serial3.begin(9600)

then send the module

<break> 0x00 0x65

then

Serial3.begin(38400)

to set for 38400

My understanding is software serial is limited to 9600 baud and is very time intensive.

NewSoftSerial is neither of these things. Though if you have a Mega with 4 hardware ports, you don't need software serial ports.

I see no reason you can't tie Rx and Tx together on the chip. Of course it will require some fancy foot work to turn around the Tx pin so the two devices don't clash.

It's possible you can't use the Serial.print etc functions, although you probably can if you wrap the transmit in the pin swap code

pinMode(txpin, OUTPUT);
Serial2.print ("xx");
pinMode(txpin, INPUT);

Sort of thing.

I know we had a similar thread about some time ago (although with software serial) and this worked.


Rob

If you use the hardware port, you'll also need to add code that discards the data you send when it "echos" into the receive buffer. Alternatively, you may be able to sneak past the Serial library code and disable the receiver while you're sending. But be aware that there's a tiny bit of hardware buffering on the transmit side, so another byte or so will go out after Serial.print() returns to your code.

Yes, you can do this just fine. By using a couple of resistors, you will prevent sending any data back to your RX from your TX:

Then, you will be able to use hardware serial like normal, including Serial.read() and Serial.write().

The resistors prevent TX and RX from pulling each other high and low, and instead let the remote end do it.

I use the same simple circuit to communicate with a hardware device that also uses a half-duplex, single-wire serial connection.

(Remember, you still need a common ground =)

!c

EDIT: I forgot to mention, if you intend to hardware this connection, make sure to put a switch to break the COM connection, otherwise you won't be able to upload sketches.

1 Like

Awesome. Thanks for the tips. I will hook up drone's circuit this week and try it out. I plan on using one of the extra serial ports on the Mega so it won't interfere with uploading.