Multiplexing serial RS-232

Go To Last Post
23 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi,

Can anyone recomend a good chip for multiplexing serial connections? I have one USART on my AVR and I wish to talk to two devices through it. I can't just use a simple 2-4 MUX for this as effectively there are three inputs and three outputs:

              -------> DEV1 RX
AVR TX ---->|
              -------> DEV2 RX


              <------- DEV1 TX
AVR RX <----|
              <------- DEV2 TX

The main requirement is that the chip is cheap, I know I could add a software USART but that is not an option.

Cheers,

John

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

CD4052
Alexander

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

You can use a logic gate, or even transistors such as 2n2222. Ive done it and it works fine.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

john_g2003 wrote:
I have one USART on my AVR and I wish to talk to two devices through it..

Need more detail on what you really want....

With no flow control, the AVR TX output could just be parallelled up and sent to both the devices' RX pins. But do you want them both to receive the same data or do you want to be able to control which device gets which data?

You could logically OR the devices' TX pins with logic gates or transistors. But might they both be transmitting at the same time?...which will make the logically OR'ed signal gibberish. And do you want to be able to determine which device sent which data?

Tell us more....

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Muxing RS232 is generally not recommended. The spec is written for one transmitting device and one receiving device at each end.

There are several problems with "just paralleling" receivers. Each has an input resistance of 1.5K Paralleling two gives the transmitter a load of 750 ohms and some simply won't drive that.

You can't just parallel transmitters, either. Each is pulling hard in one direction when not transmitting.

Analog switches can work, but they generally need to be powered from +12V and -12V since the signals can swing that far. It is difficult, however, to figure out how to control these switches.

I would strongrly recommend going to RS422 or RS485. There are good notes in the "Free Electronics" section at the top of this board.

Jim

 

Until Black Lives Matter, we do not have "All Lives Matter"!

 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I want the two devices to be isolated when they're not in use, there is a possibility they may transmit at the same time, I also do not want the devices to receive the same data.

Which version of CD4052 do you mean Alexander? I did a search and found several, who makes the one you have used?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

74HC4052 for TTL
CD4052 for +- 12V
Alexander

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

You can handle all the muxing/demuxing on the ttl side using standard gates. Then go out to a MAX232 or similar to do your level shift to RS-232.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

MartinM57 wrote:

You could logically OR the devices' TX pins with logic gates or transistors. But might they both be transmitting at the same time?...which will make the logically OR'ed signal gibberish.
Tell us more....

Actually you need to logically AND the the signals from the 2 transmitting devices to the AVR Rx not OR. The AVR Tx can be be tied directly to both of the receiving devices. As mentioned both devices will see that same data sent from the AVR and if both devices are sending at the same time the AVR will see garbage.
Or you can use a switch such as the ISL84544. Its a lot smaller solution that using logic gates. Its not that fast but it works well for lower baud rates eg (9600).

Dave

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I agree that mutiplexing serial lines is generally a bad idea. I tried it and it _sorta_ worked but was fraught with problems. MUXint the signals is the easy part but managing the MUX is difficult. If the application can have both devices sending data at the same time, data will be lost and the device cannot tell that the data is lost. Dual and quad uarts are avaialble but they are not cheap. Another option may be to write a software uart for one or both channels.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi..

I have used MAX399 and MAX3221 combination sucessfully in one of my projects to multiplex 4 RS232 ports. It worked pretty good. Here's the app note:
http://www.maxim-ic.com/appnotes.cfm/appnote_number/588

Good Luck
Shadab

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

you can use 74hc244, i am using it in one of my projects

Regards, Kapil +) ISP lines on MEGA128 NOT mapped on SPI +) Tiny4/5/9/10, Isolate Reset line from ISP before connecting it to +12V

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thanks guys I will check out the chips mentioned.

I am wondering, why is it generally a bad idea to multiplex serial lines if I only need to talk to one device at a time?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

john_g2003 wrote:
Thanks guys I will check out the chips mentioned.

I am wondering, why is it generally a bad idea to multiplex serial lines if I only need to talk to one device at a time?

Because RS232 is not a master/slave protocol. Both devices on the other side might start talking to you at (approx) the same time as mentioned in an earlier post. You will only receive one or if you've switched the receive mux off you'll hear neither. Both the transmitters think that they have completed their mission successfully and might be waiting 'till eternity for you to act.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

There seems to be some confusion on what the OP and others mean by muxing. My understanding is the OP simply wants to switch between 2 RS-232 channels, only talking to one at a time, and ignoring the other channel entirely. Using simple mux/demux logic would do this easily. Others seem to think the muxing scheme would logically OR/AND the 2 channels together in such a way that the 2 channels would walk on top of each other.

There's nothing wrong with the scheme you propose, talk to one device as long as you want, switch over when your program wants to. It's all good.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

How do you handle the situation when you are talking to device 1 and device 2 sends data?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

feralbeagle wrote:
How do you handle the situation when you are talking to device 1 and device 2 sends data?

I get the impression that the OP doesn't care what the unused device is doing unless he's talking to it. john_g2003????

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Use what we did in the old days, a [miniature] DPDT relay.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:

Use what we did in the old days, a [miniature] DPDT relay.

Wouldn't that at least partly be because you couldn't go to DigiKey in the good old days and get a 74HC257 from stock at US$0.53/qty. 1 that consumes less than 100uA and operates on 2V to 6V?

[To OP: the '257 is what we have applied in several apps to switch the UART signals between different comms drivers such as USB, RS485, & IrDA.]

Lee

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I've done this three times in the last 6 months with a super cheap Hamlin DIP pacakge reed relay w/integrated diode, and a ULN 2003 transistor array. The client wanted a cheap reliable way to multiplex 16-32 serial lines.

The only limitation is you need to wait a few hundred ms for the relay to debounce before using the line.

I've built an active serial switch as well from arrayed MAX3100's, but that cost a little bit more / lot more.

RS485 works too, but ended up being a lot more expensive than the relay solution to implement in those particular instances.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thanks guys, yes dksmall is right I dont care about talking to dev1 whilst talking to dev2, and vice versa. In my case the two devices are a modem and monitoring device. I will first collect data from the monitoring device then switch the uart to the modem and dial up a server and upload the data.

The 74HC257 device mentioned seems to be just a simple 2-4 mux. The problem with this is that even though what I'm doing is muxing 2 lines to 4, I need three inputs and three outputs, as mentioned in the original post.

Cheers,

John

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Let me guess... you are receiving GPS data and then sending it with a Telit module?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Nope! Worth a guess tho! It's a medical device that used a standard modem to upload the data.