3
votes

I'm trying to design a PCB that contains a CO2 sensor with UART interface, an Xbee module using UART and an AtMega328 chip. Because I have only a single UART on the AtMega328 I use SoftwareSerial for the CO2 module. The Xbee module is connected directly to digital pin 0 and 1 (TX, RX) on the Atmega328. This means that I would have to disconnect the Xbee if I want to program the Atmega328 and vice versa. (Edit: I would prefer to keep the Xbee connected through the hardware serial. Connecting the Xbee to SoftwareSerial would prevent me from being able to configure it and change the firmware).

In my previous attempt to solve this I used a 6-pin header and jumpers (3x2). To connect the Xbee to Serial I created a cable connecting the outer pins together, allowing me to flash the firmware of the Xbee.

I want this to be controlled by the Arduino. As far as my limited knowledge of electronics goes I would be using multiple 'double pole, double throw' switches. If I would use (for example) the NX3L2467 this would give me the following options: Switching combinations for DPDT switch

(F = FT232 UART-to-USB, D = ArDuino, X = Xbee Module). I use 5Y* and 6Y* in my example to address the 1Y* and 2Y* pins on the second switch.

This would in turn result in the following truth table: Truth table for DPDT switch

This construction would allow me to do what I want, connect Xbee to Duino, Duino to FTDI, FTDI to Xbee. Is using two of these switches the most efficient way to manage this without moving to another microcontroller? Is there an IC that would be able to switch between these devices without having two 'switches' between every connection?

2
Instead of multiplexing the uart lines you could use another interface of your µC and convert it to uart, for instance SPI2UART. This is probably not cost effective but if you use an arduino and an xbee shield I guess cost is not your main constraint.Emilien
I have a custom PCB with the SMD Arduino and Xbee Socket on it. Cost is most certainly a constraint in this project. I'll have a look at the SPI2UART project, thanks! I guess my question is not clear enough, I think I'm looking for a hardware solution, but I'm not sure whether the setup proposed in this stackoverflow question is the most effective.DJFliX

2 Answers

1
votes

The cheapest solution is using jumpers.

If you want a more "elegant" solution, instead of some switches you can use some 3-state buffers or some digital muxes and demuxes.

Here is an example:

Mux and demux example

In orange there are two muxes, in green two demuxes. F- are the FT232 pins, X- are the XBee ones and (guess what) A- are the Arduino pins.

Here is the table of the connections:

  • FT232 <-> XBee: a=0, b=1, c=1, d=0
  • FT232 <-> Arduino: a=0, b=0, c=0, d=0
  • XBee <-> Arduino: a=1, b=1, c=1, d=1

As you can see a and d are always the same, like b and c. So with two pins (or switches or jumpers) you can control it.

ad = 0 bc = 0 -> FT232 <-> Arduino
ad = 0 bc = 1 -> FT232 <-> XBee
ad = 1 bc = 1 -> XBee <-> Arduino

Instead of using muxes and demuxes you can use digital switches (if you can find a 4-switches IC you can do everything with it).

This is the "complete" solution. If you can tolerate that on the RX pin you can "sniff" the other communication, you can save one IC: you put, on each of the three RX lines, a 2:1 mux connected to the other two transmitter (so A-tx and F-tx are connected to X-rx and so on). By controlling these three muxes you can select who you want to listen to.

0
votes

In the end the solution was even simpeler. Move to a chip that has multiple UARTS. The cost of adding extra physical components (also requiring extra board space) was too high compared to just picking another MCU.