Multiplexing UART

I'm looking into UART expansion solutions before designing my next project. I've been reading about multiplexing and it seems that a multiplexer/demultiplexer will be able to expand my UART channels, with the limitation that only one channel can be used at a time.

What I'm unclear about is how I would connect BOTH the Rx and Tx port of arduino to all UART devices? I would need a 2:n MUX of some kind, correct? If I wanted 8 devices, all connecting to BOTH Rx and Tx I would need a 2:16 MUX, yes? or would I need two 1:8 MUXs?

Can you cascade/string together multiple multiplexers for further expansion / what are the limitations of doing this?

Also, I've seen mostly analog multiplexers recommended for this task yet UART is digital? I'm a quite new to electronics/ digital electronics so the plainest language possible would be most appreciated.

Thank you!

Another Atmega 328 is a simple source for an extra UART. Connect several of them to the master Arduino using SPI. Then you will have several UARTs that can work in parallel. If you can work with the smaller form-factor some of the Attinys have UARTs at a lower per-unit price.

I suspect that sort of solution would be less trouble than a multiplexer. But you have not provided a link to the datasheet for the multiplexer you are thinking of.

...R

You can connect the masters TX to all slave RX pins. You can also connect all slave TX pins to the master RX pin if you do it through a diode, 1N4148, as a pulldown. However, if two slaves try to TX at the same time then you have a collision and corrupted data. In this case, the master has to poll each slave and ask if there's data to be sent. If so, then that slave sends it's message. It requires a data packet containing at least an ID and command byte. All slaves listen but only the addressee responds. Same concept as I2C.

I helped a gentleman in Colorado rework a home automation system using this scheme with several dozen controllers and sensors and it works quite well. For the long run to the highway gate, we used a dedicated RS485 link.

AncientOracular:
I'm looking into UART expansion solutions before designing my next project. I've been reading about multiplexing and it seems that a multiplexer/demultiplexer will be able to expand my UART channels, with the limitation that only one channel can be used at a time.

What I'm unclear about is how I would connect BOTH the Rx and Tx port of arduino to all UART devices? I would need a 2:n MUX of some kind, correct? If I wanted 8 devices, all connecting to BOTH Rx and Tx I would need a 2:16 MUX, yes? or would I need two 1:8 MUXs?

Can you cascade/string together multiple multiplexers for further expansion / what are the limitations of doing this?

Also, I've seen mostly analog multiplexers recommended for this task yet UART is digital? I'm a quite new to electronics/ digital electronics so the plainest language possible would be most appreciated.

Thank you!

Mux's only work from a Master to Slave environment, if the Slave can send data without the Master requesting it, that data will be lost.

You might also look at SPI->UARTS The MAX14830, is a quad UART, it can be interfaced by SPI or I2C. This might be a simpler solution.

Chuck.

The buffers alone make it a better choice as all slaves can talk when they want to send something.

What are your thoughts on using something like this?

SparkFun Analog/Digital MUX Breakout - CD74HC4067 - BOB-09056 - SparkFun Electronics :

"Description: This is a breakout board for the very handy 16-Channel Analog/Digital Multiplexer/Demultiplexer CD74HC4067. This chip is like a rotary switch - it internally routes the common pin (COM in the schematic, SIG on the board) to one of 16 channel pins (CHANxx). It works with both digital and analog signals (the voltage can’t be higher than VCC), and the connections function in either direction. To control it, connect 4 digital outputs to the chip’s address select pins (S0-S3), and send it the binary address of the channel you want (see the datasheet for details). This allows you to connect up to 16 sensors to your system using only 5 pins!

Since the mux/demux also works with digital signals, you can use it to pipe TTL-level serial data to or from multiple devices. For example, you could use it to connect the TX pins of 16 devices to one RX pin on your microcontroller. You can then select any one of those 16 devices to listen to. If you want two-way communications, you can add a second board to route your microcontroller’s TX line to 16 device’s RX lines. By using multiple boards, you can create similar arrangements for I2C, SPI, etc.

The internal switches are bidirectional, support voltages between ground and VCC, have low “on” resistance and low “off” leakage, and to prevent crosstalk, perform “break-before-make” switching. The board also breaks out the chip’s “enable” pin, which when driven high, will completely disconnect the common pin (all switches “off”)."

It's appealing to me because you can expand the UART, I2C, and SPI, at the cost of PWM space, which, if I'm not mistaken, you can also expand via MUX/DEMUX or en/decoding. This seems (at a glance) to be the simplest solution for expanding these various channels generally, including the accommodation of 2-way serial communication, is there any reason one wouldn't want to use this device? Is there a simpler or more effective way of doing this / are there any inherent drawbacks doing it this way? Thank you for your patience and support. Your responses help a lot.

So you'd connect two of them for serial comms, one for Tx and one for Rx? That would work.
Or just Rx if it's ok for all slaves to listen to the Tx line all the time.

SPI, you connect all devices to SCK/MISO/MOSI anyway, the 4067 could be used to expand the number of slave selects.

I2C, you connect all devices in parallel, each listens for its unique slave address to respond. No mux needed, unless devices had common addresses. Then you could use the mux to select who got their clock, or data, signal connected up. No clock, or no address, should be no response.

chucktodd:
You might also look at SPI->UARTS The MAX14830, is a quad UART, it can be interfaced by SPI or I2C. This might be a simpler solution.

Looks expensive - and seems to be a surface mount component.

...R

How many slaves do you anticipating using in your system?

Digikey wants $12.75 each with a 7 week lead time. You also have the problem of finding a 48 pin breakout board and the ability to connect the chip with underside pads.

CrossRoads:
So you'd connect two of them for serial comms, one for Tx and one for Rx? That would work.
Or just Rx if it's ok for all slaves to listen to the Tx line all the time.

SPI, you connect all devices to SCK/MISO/MOSI anyway, the 4067 could be used to expand the number of slave selects.

I2C, you connect all devices in parallel, each listens for its unique slave address to respond. No mux needed, unless devices had common addresses. Then you could use the mux to select who got their clock, or data, signal connected up. No clock, or no address, should be no response.

This affirms my thinking, thank you.

Arctic_Eddie:
The buffers alone make it a better choice as all slaves can talk when they want to send something.

Sorry when you say buffers can you add to this please, I'm lost at what you mean, do you mean the diodes?
Regards

74HC4052 is perfect for that

Arctic_Eddie:
You can connect the masters TX to all slave RX pins. You can also connect all slave TX pins to the master RX pin if you do it through a diode, 1N4148, as a pulldown. However, if two slaves try to TX at the same time then you have a collision and corrupted data. In this case, the master has to poll each slave and ask if there's data to be sent. If so, then that slave sends it's message. It requires a data packet containing at least an ID and command byte. All slaves listen but only the addressee responds. Same concept as I2C.

I helped a gentleman in Colorado rework a home automation system using this scheme with several dozen controllers and sensors and it works quite well. For the long run to the highway gate, we used a dedicated RS485 link.

Hi @Arctic_Eddie, I am working in a similar project and I'd like to know if you can share a simple electrical diagram based on how the diode is connected to make the TX's from several slaves work in parallel to a single Master. Can you please provide?

Thank you!
-Ed Z.

Here is a simple schematic using three Nano boards. This assumes that pin D2 can be configured for RX and D3 for TX. More slave devices can be added with it's associated diode. The master Nano on the left would need a pullup on it's RX pin. The internal one may be enough but a lower value external is also a choice, about 10K and depending on the baud value. You need to define a data packet having at least a number for the addressee and another for a command. The master would send a message, heard by all, but intended for one, asking if, or requesting for, a data packet. That particular slave would answer with it's ID and data in another predefined packet. If you need longer cable runs then RS485 adapters and coding is a better choice. If all slaves are in the same enclosure then the diode scheme will work. I've used this scheme in an RC controlled sonar boat using four Nanos and one Mega2650. It worked quite well with baud values in the Mbps range. In that case, the pullup resistor had to be a few hundred ohms for faster rise times. You can approach the sink current rating for a single pin.

Arctic_Eddie:
Here is a simple schematic using three Nano boards. This assumes that pin D2 can be configured for RX and D3 for TX. More slave devices can be added with it's associated diode. The master Nano on the left would need a pullup on it's RX pin. The internal one may be enough but a lower value external is also a choice, about 10K and depending on the baud value. You need to define a data packet having at least a number for the addressee and another for a command. The master would send a message, heard by all, but intended for one, asking if, or requesting for, a data packet. That particular slave would answer with it's ID and data in another predefined packet. If you need longer cable runs then RS485 adapters and coding is a better choice. If all slaves are in the same enclosure then the diode scheme will work. I've used this scheme in an RC controlled sonar boat using four Nanos and one Mega2650. It worked quite well with baud values in the Mbps range. In that case, the pullup resistor had to be a few hundred ohms for faster rise times. You can approach the sink current rating for a single pin.

Hi Arctic_Eddie,
Thanks for the schematic. I am using 4 ESP32 at 2mBauds for communications. I tried this circuit but it is not working. Tried 82 ohms pullup up to 10k on the Master but still no good. I can have one ESP interfaced no problem but as soon as I connect 2 messages are garbled. Perhaps I need pull down resistors on the slaves? Not sure what else to try.

You may need an oscope to troubleshoot the problem. First though, try very low baud values, maybe 1200. Also, be sure the master RX pin sits at near Vcc when no data is being received by the master. Maybe one of the slaves is holding the line low which blocks the other slave from sending data that can be read by the master. Not familiar with the ESP32 so don't know how they handle serial ports other than the one connected to the USB download function. Essentially, the oscope should reveal the cause.