Electronic – Switching Serial Connections among several devices

multiplexerserialserial-busswitches

I have 3 devices that communicate via a serial port. Let's call them Device 1, Device 2, and Bluetooth (BT to serial adapter). The BT is used to communicate with a computer, but it can be treated just like a 3rd device for the purposes of the question. There are 3 modes I need this setup to function in. Mode A would have Device 1 be connected to the Bluetooth, Mode B would have Device 2 be connected to the Bluetooth, and Mode C would have Device 1 and Device 2 connected to each other. Please see attached image for a diagram to make things clear.

Connection Modes

I can switch between modes with a 3 way switch or a button. What I am looking for is a way to switch between these 3 modes. I have considered just using a mechanical switch, but given the number of connections, and considering that my final project needs to be very small, this is impractical.

My ideal solution would be to use some kind of IC that would allow me to foreword a serial signal from one pin to another, depending on the mode selected, or a set of transistors that would allow me to switch between different modes. But I am completely open to any other, better, solution.

Any help or pointers in the right direction would be very appreciated. Thank you!

Best Answer

In the general case, you need a 2:1 multiplexer in front of each RX input.

If you know the unconnected device will not be lowering its TX output (I'm assuming the line idle level is high), then just a 2-input AND gate in front of each RX input will do it.

Or, you can use the AND gate trick with a OR gate on each TX output. That explicitly masks off the unused device by forcing the OR output high when that device is not in use. The extra input to each OR gate enables that device when low and disables it when high.