Author Topic: 2 UART on a single port  (Read 3964 times)

0 Members and 1 Guest are viewing this topic.

Offline chrischinaTopic starter

  • Contributor
  • Posts: 12
  • Country: hk
2 UART on a single port
« on: May 13, 2016, 03:17:22 am »
I am curently working on a project where a MCU got only one UART port available, however I need to run two peripherals with UART interface (not simultaneously) so I was wondering if I can connect two peripherals UARTs on the same UART of the MCU while playing with enabling and disabling the peripherals one by one for communicating with the MCU?

Your feedbacks and recommendation are appreciated about this situation

Regards
 

Offline Signal32

  • Frequent Contributor
  • **
  • Posts: 251
  • Country: us
Re: 2 UART on a single port
« Reply #1 on: May 13, 2016, 03:26:24 am »
What you're trying to do should work.
You'll have to use diodes to/from the devices.
You could also use MOSFET's(controlled by a PIN of your MCU) to choose which RX+TX lines are connected to the inputs of the MCU
 

Offline digsys

  • Supporter
  • ****
  • Posts: 2209
  • Country: au
    • DIGSYS
Re: 2 UART on a single port
« Reply #2 on: May 13, 2016, 03:53:38 am »
For TXD - If you don't mind if both (all) devices receive data (and ignore stuff not for them, or are already off), you can TXD to all.
Maybe use separate buffers. For RXD, you can either use an O/C OR/NOR gate and only the device TXD'ing will be received.
IF neither of these are suitable, you can use 1 port O/P pin to either select or disable one device. Basically, it's a Network.
Hello <tap> <tap> .. is this thing on?
 

Offline newbrain

  • Super Contributor
  • ***
  • Posts: 1719
  • Country: se
Re: 2 UART on a single port
« Reply #3 on: May 13, 2016, 06:29:26 am »
I am curently working on a project where a MCU got only one UART port available, however I need to run two peripherals with UART interface (not simultaneously) so I was wondering if I can connect two peripherals UARTs on the same UART of the MCU while playing with enabling and disabling the peripherals one by one for communicating with the MCU?

Your feedbacks and recommendation are appreciated about this situation

Regards
In addition to the advice already presented, here's still another alternative, depending on the MCU:

Several MCU can map peripherals to different I/O pins, even independently for Rx/Tx; e.g. for STM32s all it takes is a couple of GPIO pin redefinitions.
You could exploit this to switch the UART from one device to the other (possibly only the MCU Rx, as digsys says), without added HW or open drain/diode/chip select arrangements.
Nandemo wa shiranai wa yo, shitteru koto dake.
 

Offline Ian.M

  • Super Contributor
  • ***
  • Posts: 12860
Re: 2 UART on a single port
« Reply #4 on: May 13, 2016, 08:21:07 am »
... or there's the analog switch option: 74HC4053 triple SPDT switch.  Use pullups on the switched TX outputs to keep them in the correct idle state.   In all cases, the inactive serial device must *NOT* send data when its deselected, so if there is any possibility of that, it had better support  handshaking (hardware or XON/XOFF) and you'd better implement it!
 

Offline JPortici

  • Super Contributor
  • ***
  • Posts: 3461
  • Country: it
Re: 2 UART on a single port
« Reply #5 on: May 13, 2016, 11:37:16 am »
i have to do just the same in a forecoming project: a "bridge" between three products that now needs to communicate together, that already talk in pair using uart. one master and two slaves, i was thinking about using a 4053 to select which slave to communicate to
 

Offline Wilksey

  • Super Contributor
  • ***
  • Posts: 1329
Re: 2 UART on a single port
« Reply #6 on: May 13, 2016, 05:51:00 pm »
What about a software UART?
 

Offline rstofer

  • Super Contributor
  • ***
  • Posts: 9890
  • Country: us
Re: 2 UART on a single port
« Reply #7 on: May 13, 2016, 11:49:03 pm »
Maybe take a step back and consider creating an RS485 bus with multi-master capability.
http://bdmicro.com/code/robin/

It depends on the peripherals, of course...
 

Offline chrischinaTopic starter

  • Contributor
  • Posts: 12
  • Country: hk
Re: 2 UART on a single port
« Reply #8 on: May 14, 2016, 06:38:35 am »
What about a software UART?
I want toi avoid bit banging if possible... it makes software more complicated and I read it consume more ressources on the PU
 

Offline chrischinaTopic starter

  • Contributor
  • Posts: 12
  • Country: hk
Re: 2 UART on a single port
« Reply #9 on: May 14, 2016, 06:43:23 am »
... or there's the analog switch option: 74HC4053 triple SPDT switch.  Use pullups on the switched TX outputs to keep them in the correct idle state.   In all cases, the inactive serial device must *NOT* send data when its deselected, so if there is any possibility of that, it had better support  handshaking (hardware or XON/XOFF) and you'd better implement it!

The mcu would be CC1310 or CC2650
 

Offline Ian.M

  • Super Contributor
  • ***
  • Posts: 12860
Re: 2 UART on a single port
« Reply #10 on: May 14, 2016, 07:56:25 am »
Interrupt driven soft UARTs get processor intensive at high baud rates.  For full duplex, you need a timer interrupt at a minimum of double the baud rate, ideally 4 times so to support 9600 baud you'd typically have an interrupt every 26us - which is a nightmare on anything with high interrupt latency or low MIPS.   If they are bitbanged from the foreground execution thread, they are a nightmare at low baud rates and/or high character rates, as they block for the duration of each character. This also means you cant do full duplex.

However your MCU datasheets say: "All Digital Peripheral Pins Can Be Routed to any GPIO"
so the switch/multiplexer facility is internal to your MCU and you can take newbrain's advice above and remap the hardware UART between two separate sets of pins on the fly.

I2C or SPI interface UART chips are available (albeit a little expensive) and your MCUs support both I2C and SPI, so that's another option.
 

Offline Raj

  • Frequent Contributor
  • **
  • Posts: 694
  • Country: in
  • Self taught, experimenter, noob(ish)
Re: 2 UART on a single port
« Reply #11 on: May 14, 2016, 12:31:39 pm »
try opto couplers, though it will reduce baud rate capabilities
 

Offline gauravmp

  • Regular Contributor
  • *
  • Posts: 77
  • Country: us
Re: 2 UART on a single port
« Reply #12 on: May 24, 2016, 03:58:38 am »
I'd definitely give it a shot by using a few tri-state buffers to act an enablers/disablers although you'd have to keep perfect track of your delays.

Good Luck!
 

Offline digsys

  • Supporter
  • ****
  • Posts: 2209
  • Country: au
    • DIGSYS
Re: 2 UART on a single port
« Reply #13 on: May 24, 2016, 04:37:37 am »
Quote from: gauravmp
I'd definitely give it a shot by using a few tri-state buffers to act an enablers/disablers although you'd have to keep perfect track of your delays. 
Usual practice is to use a LM555 in re-trigger mode, Txd triggers the 555 Input and has a PW such that - MIN PW =~ 2x(min baud). That gives you 1 byte
safety margin. You can go much longer .. I've gone to 10X for high capacitance lines. RS232 is RARELY ever fast turn around, so having a dead time is fine.
Hello <tap> <tap> .. is this thing on?
 

Offline mikeselectricstuff

  • Super Contributor
  • ***
  • Posts: 13747
  • Country: gb
    • Mike's Electric Stuff
Re: 2 UART on a single port
« Reply #14 on: May 24, 2016, 05:51:24 am »
Quote from: gauravmp
I'd definitely give it a shot by using a few tri-state buffers to act an enablers/disablers although you'd have to keep perfect track of your delays. 
Usual practice is to use a LM555 in re-trigger mode, Txd triggers the 555 Input and has a PW such that - MIN PW =~ 2x(min baud). That gives you 1 byte
safety margin. You can go much longer .. I've gone to 10X for high capacitance lines. RS232 is RARELY ever fast turn around, so having a dead time is fine.
Or just use the TX complete interrupt to control bus enables
Youtube channel:Taking wierd stuff apart. Very apart.
Mike's Electric Stuff: High voltage, vintage electronics etc.
Day Job: Mostly LEDs
 

Offline andre_teprom

  • Regular Contributor
  • *
  • Posts: 71
  • Country: br
    • Aluis-Rcastro
Re: 2 UART on a single port
« Reply #15 on: May 24, 2016, 07:38:02 pm »
What you're trying to do should work.
You'll have to use diodes to/from the devices.

This works fine.
I've already done:

"Part of the world that you live in, You are the part that you're giving" ( Renaissance )
 

Offline suicidaleggroll

  • Super Contributor
  • ***
  • Posts: 1453
  • Country: us
Re: 2 UART on a single port
« Reply #16 on: May 24, 2016, 07:47:21 pm »
I've done this before using a couple of tristate buffers as a mux, worked fine.
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf