Go Down

Topic: two devices sharing a serial line (Read 2029 times) previous topic - next topic

fxmech

I was wondering if its possible to hook up two devices to the arduinos tx/rx lines.
I have a touchscreen lcd monitor from sparkfun that receives and sends info via serial pins 0/1
I also plan to use an xbee module to connect this device to a transmitting unit... also serial data.

Is it necessary to use a larger arduino with multiple serial ports or can I  hook them up to the same serial line...
The xbee transmits header lines and the screen is also looking for specific headers....

The reason I thought it could possibly work is that the xbee is only receiving data not transmitting so no data to get scrambled on the tx.  but when data comes in there will be packets from the xbee as well as serial commands coming from the lcd control library to the screen.

Will the packets stay intact or will they get scrambled if the arduino tries to talk to the monitor at the same time xbee data is coming in???

products:

https://www.sparkfun.com/products/11741

https://www.sparkfun.com/products/10854

CrossRoads

Data will be corrupted if two devices are both transmitting together.

Arduino can Tx to multiple Rx at the same time.
For Arduino to successfully Rx, only one device can Tx at a time.
Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.

K5CZ

Maybe you could try to use the hardware UART for one device and SoftwareSerial for another one. Or take advantage of the XBee can communicate not only via UART.

The serial pins (DIN and DOUT) of the XBee are connected through an SPDT switch, which allows you to select a connection to either the UART pins (D0, D1) or any digital pins on the Arduino (D2 and D3 default).

Note: hw TX and RX is problematic to use because the hardware UART is shared with the USB programmer. Programming Arduino does not work with any serial devices connected to D0 and D1 (it must be disconnected first - it extends time of the debugging)

michinyon

Mega has four hardware serial, does that solve your problem ?

jlsilicon

#4
Jul 03, 2017, 04:05 am Last Edit: Jul 04, 2017, 03:51 pm by jlsilicon
I think it would be possible (and I am going to try this),
- if you have 2 listeners (slaves), and 1 Master.

You could use the SPI/I2C circuitry, as the Open-Collector, using Diodes.
These are using the Arduino Tx & Rx cmos I/Os - Not any Rs232 / USB lines.

Tx1/Rx1 = Master
Tx2/Rx2 , Tx3/Rx3 = Slaves 2 & 3

Tx1 >---------+-------> Rx2
                             |
                            +-------> Rx3

                20K
  V+ O-/\/\/-+
                             |    D1
Rx1 <---------+-->|---< Tx2
                             |    D2
                            +-->|---< Tx3

This way the Master-1 can command Slave-2 and Slave-3 individually.
While Slaves 2 & 3 only reply when requested by the Master.

jlsilicon

#5
Jul 03, 2017, 04:16 am Last Edit: Jul 03, 2017, 04:18 am by jlsilicon
Another way to Solve this problem, would be using the SPI MISO - MOSI method.

You could connect TX1 -> RX2 , TX2 -> RX3 , TX3 -> RX1 , (or more ...)
While, using a Chain Loop method, by starting messages with a destination ID,
- and pass the Messages down the Chain until the ID Receiver receives the message.

TX1 -> RX2
             TX2 -> RX3
RX1 <-------- TX3

Robin2

You can connect several devices to a single Rx provided you isolate them properly and provided only one device talks at any one time. 

You need an external pullup resistor (4700 ohms should be ok) between the Rx pin and 5v. And on each incoming line you need a diode that prevents the HIGH on the incoming line from reaching the Rx pin. That allows any device to pull the Rx pin LOW

...R
Two or three hours spent thinking and reading documentation solves most programming problems.

Go Up