Pages: [1]   Go Down
Author Topic: Sharing HardwareSerial with XBee in Arduino  (Read 1537 times)
0 Members and 1 Guest are viewing this topic.
Toledo - Spain
Offline Offline
Newbie
*
Karma: 0
Posts: 6
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

When using ATMega328 (i.e. Arduino Uno) and XBee-Arduino library, this is design to share HardwareSerial (pins 0 and 1).
If you want to upload new firmware to arduino using USB cable you have to unplug XBee.
I'm working in a project I want to upload new firmware to Arduino without unplugging XBee.
Does anyone have done something similar??
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 44
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

You could use the softwareSerial-library
http://arduino.cc/hu/Reference/SoftwareSerial
With this library you could use other pins for serial communication and also connect multiple Xbees if you need.
But I suppose your "Xbee Arduino lib" mentioned above, doesn't work with this software connection.
Logged

Toledo - Spain
Offline Offline
Newbie
*
Karma: 0
Posts: 6
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I have used SoftwareSerial in other project, with successed, but there are two reasons I need to use hardware serial here.

1st. XBee-Arduino library is designed to use HardwareSerial. This library use API UART mode for XBee to build more sophisticated applications, that I need for this project.

2nd. HardwareSerial support asynchronous communications, needed when MPU is busy in other tasks, as 8-bit MPU are not design to run multiple threads. As I can understand, Hardware serial use hard shift-registers as a way of buffering tx and rx, while SoftwareSerial are not real asynchronous as they use RAM to buffer. A busy MPU could drive to data lose if softserial is used.

So, what I'm looking for is the way to switch Arduino Uno UART to USB when I try to upload new arduino firmware and switch Arduino Uno UART to XBee when USB is not connected.
Anyone have a clue?
Logged

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

Sounds like you will need some external hardware but the trouble with that is you don't really have access to the pins to insert some logic.

What about using a Mega with more hardware UARTs?

If you are using an Arduino with a DIP processor you can make a small board to switch the signals. You could also remove the 1k protection resistors and bodge up some hardware in their place.

______
Rob
« Last Edit: February 21, 2012, 06:12:53 am by Graynomad » Logged

Rob Gray aka the GRAYnomad www.robgray.com

Offline Offline
Newbie
*
Karma: 0
Posts: 44
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I think the reason why you can't upload sketches along the Xbee is connected, is that the Xbee's TX line is high (in idle state). So any other data connected on this bus interferes with it and gets lost. (please tell me if I'm wrong)
I am thinking of a diode that blocks any high signal coming out of the Xbee TX-line (making an open-collector-output) and pulling it high with a pullup. So if data arrives along the other lines, it shouldn't interfere with the idle state of the Xbee (as long as the Xbee doesn't send anything during uploading).

I'm not shure if that works, feel free to correct me
Logged

Toledo - Spain
Offline Offline
Newbie
*
Karma: 0
Posts: 6
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I'm thinking more about a 3-state buffer to enable or disable XBee line. But I wanted to know if anyone have experience with it, if someone have faced the problem and delays add by buffers are not relevants.
Logged

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

A buffer won't affect the signal because of delays. You could use 2 74xx125s and two 74xx126s. Just off the top of my head maybe something like this



When the chip is reset for programming the IO pin goes tri-state and the resistor enables U1 and U2. After programming the first thing you do is set the IO pin high to enable U3 and U4 and therefore the XBEE.

Technically you don't need buffers on Tx but it's cleaner and stops the XBEE from trying to decipher all the programming traffic.

It needs a spare IO pin though and I don't know how you would insert U1 and U2 into the signal path unless you have a DIP mega328.

_____
Rob
Logged

Rob Gray aka the GRAYnomad www.robgray.com

Toledo - Spain
Offline Offline
Newbie
*
Karma: 0
Posts: 6
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Great! I think this is the solution. Just notice that if you want USB port for debugging, U1 and U2 are not needed. Now I need a 74X125 to test and share results, but thanks to Rob smiley-wink
Logged

Western New York, USA
Offline Offline
Faraday Member
**
Karma: 40
Posts: 4395
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
I'm working in a project I want to upload new firmware to Arduino without unplugging XBee.
Have you considered uploading new firmware via the ICSP interface?  This approach would also free up some flash memory (bootloader area) if you need it.

Don
Logged

Toledo - Spain
Offline Offline
Newbie
*
Karma: 0
Posts: 6
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Sure! But this is not user friendly smiley-wink I'm thinking about firmware update application for end-user.
Logged

Global Moderator
Boston area, metrowest
Offline Offline
Brattain Member
*****
Karma: 547
Posts: 27363
Author of "Arduino for Teens". Available for Design & Build services. Now with Unlimited Eagle board sizes!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Xbee is also 3.3V interface, yes? So you need 3.3V level conversion also.
Look at TXB0104 for the interface
http://www.ti.com/product/txb0104
Logged

Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

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

You can leave U1 and U2 in, just swap the IO pin level depending on whether you want to talk to the PC or the XBEE. That way you aren't spewing XBEE crap up to the PC. Anyway you really still have to isolate the FTDIs TX output.

CR is right about the level conversion, you could replace U3 and U4 with a TXB0104 (or TXB0102).

______
Rob
Logged

Rob Gray aka the GRAYnomad www.robgray.com

Offline Offline
Newbie
*
Karma: 0
Posts: 44
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

One question (Sorry if I interrupt your conversation)
Quote
Anyway you really still have to isolate the FTDIs TX output.
Why does he have to isolate it? Wouldn't it just work if he connects or disconnects only the Xbee's TX output (as he did it before by unplugging the whole Xbee)?
Logged

Salem, Oregon
Offline Offline
Sr. Member
****
Karma: 7
Posts: 310
Friends don't let friends use Strings
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

So, what I'm looking for is the way to switch Arduino Uno UART to USB when I try to upload new arduino firmware and switch Arduino Uno UART to XBee when USB is not connected.

Well I didn't see this mentioned, but there is an interesting blog post I ran into (http://www.billporter.info/how-to-add-multiple-uart-connections/) that suggests using a pair of 1K resistors on the xmit/receive lines.

This is on my "to-do" list to experiment with but I haven't actually tried it so YMMV, but I thought it might help.

Brad (KF7FER)
Logged

Pages: [1]   Go Up
Jump to: