Pages: [1]   Go Down
Author Topic: Single Wire Hardware Serial, Possible?  (Read 4273 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 5
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Atlanta
Offline Offline
Sr. Member
****
Karma: 1
Posts: 254
Arduino still rocks
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset


[url]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
Code:
Serial3.begin(9600)
then send the module
Code:
<break> 0x00 0x65
then
Code:
Serial3.begin(38400)
to set for 38400
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 601
Posts: 48543
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
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.
Logged

nr Bundaberg, Australia
Offline Offline
Tesla Member
***
Karma: 126
Posts: 8471
Scattered showers my arse -- Noah, 2348BC.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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

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

« Last Edit: January 22, 2011, 02:06:19 am by graynomad » Logged

Rob Gray aka the GRAYnomad www.robgray.com

Rural Arizona
Offline Offline
Edison Member
*
Karma: 7
Posts: 1711
Incorrigible tinkerer
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

0
Offline Offline
Sr. Member
****
Karma: 4
Posts: 323
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
« Last Edit: January 22, 2011, 05:03:19 pm by drone » Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 5
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Pages: [1]   Go Up
Jump to: