6 serial ports to 1

Hi all,

I have to combine the hardware TX line of 6 atmega328 processors to a single serial TX line.
If I can make sure that every processor spits its data when no other processor is talking, I assume that I can simply do with a OR gate with six inputs? Or is this too easy?

I have never worked with gate ICs before. What are the important factors to look for? Does is need to be a special kind capable of working with TTL level signals?

Thanks!
Jens

jensvanhoof:
Hi all,

I have to combine the hardware TX line of 6 atmega328 processors to a single serial TX line.
If I can make sure that every processor spits its data when no other processor is talking, I assume that I can simply do with a OR gate with six inputs? Or is this too easy?

That will work if you can avoid clashes.

You could wire the RX line back to all 6 atmega328s and tell them when to talk to you.

jensvanhoof:
I have never worked with gate ICs before. What are the important factors to look for? Does is need to be a special kind capable of working with TTL level signals?

It doesn't need to be anything special. 74LS32 is the standard one. A 74HC4078 will do it with a single chip if you can find one of them.

You can do that with gates, but I would like to know more.

How can you test that no other is talking ? With an extra signal ? When you use an extra signal, you can use that also for other things.

You could use a multiplexer:

You could daisy chaining the serial data lines:

You could use the SoftwareSerial, but you would have to know which one will be transmitting, since it can only receive one pin:

The other way would be to use the I2C interface which is designed to have several devices attached to it.

Caltoa:
You can do that with gates, but I would like to know more.

How can you test that no other is talking ? With an extra signal ? When you use an extra signal, you can use that also for other things.

If you wire the RX line back to TX on the others you could send a '1' to give number 1 the right to talk, a '2' to give number 2 the right to talk, etc.

If you wire the RX line back to TX on the others you could send a '1' to give number 1 the right to talk, a '2' to give number 2 the right to talk, etc.

That was exactly the idea. Each of the 6 processors will itself collect serial data through its hardware serial port and process the data to another format. A 7nd processor will authorize the other 6 to talk one after another. I was thinking to use 6 pins for that and run them to an interrupt line of the 6 others. I can afford to sacrifice 6 pins for this as I don't need a lot of other I/O.

Then collect all 6 TX lines to that OR gate, and feed that into a MAX232 to go to a SUBd9 connector.
Does that makes sense?

I also found this chip: http://cds.linear.com/docs/en/datasheet/1039fd.pdf which seems to offer the ability to combine multiple outputs directly, although I don't fully understand how to do that. I don't have a lot of experience with both electronics and decrypting datasheets :slight_smile:

If you wire the RX line back to TX on the others

Wouldn't that be the other way around? TX back to the RX on the others?

jensvanhoof:

If you wire the RX line back to TX on the others

Wouldn't that be the other way around? TX back to the RX on the others?

Yes. :blush:

If you're giving the others "Right to talk" then you can do it with no special extra hardware.

The trick is to call "Serial.end()" and set your TX pin to "INPUT" when you don't have the right to talk. This way you're not putting any load on the line and other Arduinos can use it freely.

For safety you could put a 220 Ohm resistor in each TX line - just in case there's a bug in the software and the arbitration fails. This will limit current to safe levels (there's 440 Ohms between any two transmitters).

From my perspective you are trying to reinvent the wheel.
So if you need communication from 6 devices use i2C for that.
RS232 lines shouldn't be shared with another devices(at least not recommend) and the I2C bus was born to situations like you want to do.
You could argue "but this will also work" ok fear enough but you will get in trouble.You have to buy the chips(max232 ...), wire all together ...
With I2C all you need are 2 pull-up resistors and code!

That actually makes sense. I have only used I2C before were my Arduino acted as the master and so never noticed that there is an optional argument on Wire.begin() [EDIT] and so using the atmega as a slave…

So, just wire all SDA and SCL lines together, pull both lines up to VCC with a 1K resistor then?

jensvanhoof:
So, just wire all SDA and SCL lines together, pull both lines up to VCC with a 1K resistor then?

Yep.

(Well, most docs say 4.7k for the resistor, but 1k will work too)

With that setup, any Arduino can talk to any other (so long as you figure out the bus arbitration).

Allright, I'll give that a try! Thanks!

nb. You don't need any bus arbitration in this configuration. Just give the 6 slaves a different I2C address and the master does all the talking.

Nick has a nice writeup on using Arduinos as master/slave.

You will have multiple slave, give each its address - maybe have them read three pins that you pull low or leave disconnected for high. Then you just have 1 slave program, and each board figures out its address in setup.

I have done something similar, using one of these guys: 16 Channel Multiplexer - COM-00299 - SparkFun Electronics

I have to combine the hardware TX line of 6 atmega328 processors to a single serial TX line.
If I can make sure that every processor spits its data when no other processor is talking, I assume that I can simply do with a OR gate with six inputs? Or is this too easy?

Probably easier than that. Try putting a small signal diode in each of the tx lines with the band end of the diode connected to the slave tx pin.