2 UART on a single port - Page 1
Forum section: electronics / general

author: chrischina
author_rank: Contributor
timestamp: May 13, 2016, 03:17:22 am
content: 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 situationRegards

author: Signal32
author_rank: Frequent Contributor
timestamp: May 13, 2016, 03:26:24 am
content: 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

author: digsys
author_rank: Unknown
timestamp: May 13, 2016, 03:53:38 am
content: 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.

author: newbrain
author_rank: Super Contributor
timestamp: May 13, 2016, 06:29:26 am
content: Quote from: chrischina on May 13, 2016, 03:17:22 amIn 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.

author: Ian.M
author_rank: Super Contributor
timestamp: May 13, 2016, 08:21:07 am
content: ... 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!

author: JPortici
author_rank: Super Contributor
timestamp: May 13, 2016, 11:37:16 am
content: 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

author: Wilksey
author_rank: Super Contributor
timestamp: May 13, 2016, 05:51:00 pm
content: What about a software UART?

author: rstofer
author_rank: Super Contributor
timestamp: May 13, 2016, 11:49:03 pm
content: 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...

author: chrischina
author_rank: Contributor
timestamp: May 14, 2016, 06:38:35 am
content: Quote from: Wilksey on May 13, 2016, 05:51:00 pmI want toi avoid bit banging if possible... it makes software more complicated and I read it consume more ressources on the PU

author: chrischina
author_rank: Contributor
timestamp: May 14, 2016, 06:43:23 am
content: Quote from: Ian.M on May 13, 2016, 08:21:07 amThe mcu would be CC1310 or CC2650

author: Ian.M
author_rank: Super Contributor
timestamp: May 14, 2016, 07:56:25 am
content: 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.

author: Raj
author_rank: Frequent Contributor
timestamp: May 14, 2016, 12:31:39 pm
content: try opto couplers, though it will reduce baud rate capabilities

author: gauravmp
author_rank: Regular Contributor
timestamp: May 24, 2016, 03:58:38 am
content: 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!

author: digsys
author_rank: Unknown
timestamp: May 24, 2016, 04:37:37 am
content: Quote from: gauravmpUsual 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 bytesafety 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.

author: mikeselectricstuff
author_rank: Super Contributor
timestamp: May 24, 2016, 05:51:24 am
content: Quote from: digsys on May 24, 2016, 04:37:37 amOr just use the TX complete interrupt to control bus enables

author: andre_teprom
author_rank: Regular Contributor
timestamp: May 24, 2016, 07:38:02 pm
content: Quote from: Signal32 on May 13, 2016, 03:26:24 amThis works fine.I've already done:

author: suicidaleggroll
author_rank: Super Contributor
timestamp: May 24, 2016, 07:47:21 pm
content: I've done this before using a couple of tristate buffers as a mux, worked fine.