How do I use two uart devices  on one port like one device - Page 1
Forum section: electronics / beginners

author: abdullahseba
author_rank: Frequent Contributor
timestamp: July 03, 2017, 11:10:41 am
content: HiI have two arduino based circuits with an LCD and a keypad.I dont need them to be independently controlled but when I connect them to the same port directly, I can send to both units but not receive. when connected to the arduino I cant do either.How can I achieve this? Is there a sort of splitter circuit I can use?Thanks in advance.

author: Aodhan145
author_rank: Frequent Contributor
timestamp: July 03, 2017, 11:18:18 am
content: Why do you not use two ports if they are two devices?RS232 is usually a one to one interface.You can try using it like thisPC TX - µC1 RXµC1 TX - µC2 RXµC2 TX - PC RXThen write an addressing kind of protocol where you give an identifier to tell µC1 to keep the packet or transfer it to µC2Then an identifier for µC2 if it should keep the packet or send it to the PCThe PC should listen for the identifier to tell what device is sending the packet.Another method would be to have µC1 usart just connected straight to the PC and then use some sort of software serial to communicate with µC2 from µC1. That's also a bad idea unnecessary overheads and having the device to do another functions that are completely unnecessary. Especially a software serial which requires constant polling on the pins and bit banging as you are no longer using the peripheral designed for it.You could also have some kind of analog switch connected to the PC RX and µC's TXs then they wait until the have control by checking the other µCs state have some GPIO saying they are transmitting then switch the transmission depending on which ones need to communicate. This is probably a bad idea as well but it is more like what you are asking for.Keep in mind this is a terrible idea and you can just use two ports.If you want to transmit to both and you are using two ports only use on ports TX pin but the two RX pins so you can independently receive.

author: testian
author_rank: Regular Contributor
timestamp: July 03, 2017, 11:25:40 am
content: You should not connect more than 2 serial output port in parallel.The best would be to use a dedicated interface for each µC.

author: abdullahseba
author_rank: Frequent Contributor
timestamp: July 03, 2017, 11:31:46 am
content: Quote from: testian on July 03, 2017, 11:25:40 amBecause I'm using the Omega2 as the controller which _has_ two ports but one is for the terminal so I'm left with one.Addressing is a bit complex for a simple thing like this, all I'm doing is sending human readable text directly to the LCD and print whatever button is pressed.I dont get why it doesn't work because both will be receiving exactly the same thing at the same time.

author: Kjelt
author_rank: Super Contributor
timestamp: July 03, 2017, 12:22:27 pm
content: More then two devices you need to go to a simple network topology, in your case for instance RS485. Just a simple RS485 interface driver is sufficient.In any case if you want to still use 232 or 485 you still need some sort of protocol, because if two devices sent at the same time the receiver will get garbage.So there needs to a protocol , simple one is that there is for instance only one master that is allowed to initiate data, and the other devices (slaves) will listen.You need to implement addressing in the protocol and a command so that the master can target a specific slave (optional checksum and startbyte for synchronisation and integrity).

author: Rerouter
author_rank: Super Contributor
timestamp: July 03, 2017, 12:40:30 pm
content: or you make it a 4 wire serial connection, with clear to send and ready to send for each device, as long as they respect those lines and tristate when done, you should be fine to go protocol free. (just include some current limiting resistors in case you make a mistake)

author: rstofer
author_rank: Super Contributor
timestamp: July 03, 2017, 01:35:56 pm
content: You simply can't have two totem-pole outputs talking on a single wire. One output talking to two inputs is fine. Two outputs talking to one input, not good! As soon as one output goes high while the other goes low it causes a short circuit.You might be able to set the Tx output to tri-state but I haven't tried it. This will eliminate the short circuit when one output is '1' and the other is '0'. Now you have to get the two units to agree on who is supposed to be talking and who is supposed to be idling.As discussed above, RS485 is the way to do this. Here is some very nice code for creating a network:http://www.bdmicro.com/code/robin/You can also use some kind of multiplexer with the select line driven by the master. The master selects which device it wants to listen to. A 2:1 multiplexer is all it takes. For 3.3V logic, this should work:http://www.analog.com/media/en/technical-documentation/data-sheets/ADG3248.pdf

author: abdullahseba
author_rank: Frequent Contributor
timestamp: July 03, 2017, 02:29:36 pm
content: Quote from: rstofer on July 03, 2017, 01:35:56 pmI did think of a multiplexer but I need both to be listened to at the same time.The omega2 has no RS485 and I have already designed and made the PCB using the ardunios only serial as the man communication port.I think my only solution would to do use the ATmega2560 or 640 as a spiltter. Both have 4 ports and this seemed to do the trick:Code:while (Serial2.available() > 0) {char inByte = Serial2.read();Serial.write(inByte);}Software serial was too slow because it had to be selected each time.