Author Topic: How do I use two uart devices on one port like one device  (Read 1381 times)

0 Members and 1 Guest are viewing this topic.

Offline abdullahseba

  • Frequent Contributor
  • **
  • Posts: 335
  • Country: gb
How do I use two uart devices on one port like one device
« on: July 03, 2017, 11:10:41 am »
Hi
I 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.
This is my right hand this is my wrong hand
 

Offline Aodhan145

  • Frequent Contributor
  • **
  • Posts: 401
  • Country: gb
Re: How do I use two uart devices on one port like one device
« Reply #1 on: July 03, 2017, 11:18:18 am »
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 this
PC TX - µC1 RX
µC1 TX - µC2 RX
µC2 TX - PC RX

Then write an addressing kind of protocol where you give an identifier to tell µC1 to keep the packet or transfer it to µC2

Then an identifier for µC2 if it should keep the packet or send it to the PC

The 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.
« Last Edit: July 03, 2017, 11:26:51 am by Aodhan145 »
 
The following users thanked this post: abdullahseba

Offline testian

  • Regular Contributor
  • *
  • Posts: 54
Re: How do I use two uart devices on one port like one device
« Reply #2 on: July 03, 2017, 11:25:40 am »
You should not connect more than 2 serial output port in parallel.
The best would be to use a dedicated interface for each µC.
 
The following users thanked this post: abdullahseba

Offline abdullahseba

  • Frequent Contributor
  • **
  • Posts: 335
  • Country: gb
Re: How do I use two uart devices on one port like one device
« Reply #3 on: July 03, 2017, 11:31:46 am »
You should not connect more than 2 serial output port in parallel.
The best would be to use a dedicated interface for each µC.
Because 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.
This is my right hand this is my wrong hand
 

Offline Kjelt

  • Super Contributor
  • ***
  • Posts: 5845
  • Country: nl
Re: How do I use two uart devices on one port like one device
« Reply #4 on: July 03, 2017, 12:22:27 pm »
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).
 
The following users thanked this post: abdullahseba

Offline Rerouter

  • Super Contributor
  • ***
  • Posts: 4624
  • Country: au
  • Question Everything... Except This Statement
Re: How do I use two uart devices on one port like one device
« Reply #5 on: July 03, 2017, 12:40:30 pm »
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)
 
The following users thanked this post: abdullahseba

Offline rstofer

  • Super Contributor
  • ***
  • Posts: 7413
  • Country: us
Re: How do I use two uart devices on one port like one device
« Reply #6 on: July 03, 2017, 01:35:56 pm »
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

 
The following users thanked this post: abdullahseba

Offline abdullahseba

  • Frequent Contributor
  • **
  • Posts: 335
  • Country: gb
Re: How do I use two uart devices on one port like one device
« Reply #7 on: July 03, 2017, 02:29:36 pm »
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
I 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: [Select]
while (Serial2.available() > 0) {
    char inByte = Serial2.read();
    Serial.write(inByte);
  }
Software serial was too slow because it had to be selected each time.
This is my right hand this is my wrong hand
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf