Two serial ports using one usart

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

I am designing a project which needs 3 serial ports. I am using a Mega128. One serial port is needed for high speed comms and the other two, will be slow speed ports. I will call them port A and B. First of all, for many reasons, I can't use any software serial ports. So, I am wodering if anyone here has tried this before. I was thinking of using 2 RS-232 converters (1 for each port) and a 4066 IC - bilateral switch. Then have the Mega128 control the switching. Also, both 'slave' devices will have a Mega16 controlling them. So, things will be flexable there also. Everything is okay when MEGA128 (Master) is transmitting, but how will the slave devices, on either port, be able to signal the Mega128 it has data to send. The use of another control line like a CTS or RTS might work or I could use a RS-485 like scheme and daisy chain both slaves on the same port. That way eliminating the need for the 4066 IC. Well, I await your suggestions and thank all who repond in advance. Happy Holidays... :)

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

Maxim makes some nice I2C uarts Max3100 series , maybe a little Tiny2313 or Mega8 could do as well (i mean receive from uart , and send to M128 via I2C or SPI).

RS485 is also for multi slaves ....

I think a 4053 has been used on the STK200 (schematics are available) as an analog switch for the 2'nd M128 uart.

But the main prob would be that you might miss a char on one "channel" while serving the other.

/Bingo

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

This is just untried thoughts:
Each m16 would need 2 pins connected to the m128 - 1 to ask permission to send and indicate when it is finished and the other to receive ok to send from the m128.
I suspect that a 4066 isn't needed and that a couple of diodes would suffice.

Ralph Hilton

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

hilander7 wrote:
I am designing a project which needs 3 serial ports. I am using a Mega128.

I recently did a project with the Mega128 where I needed 5 serial ports. I implemented the additional ports with the SPI based MAX3100 UART. It's a little pricey - I think it was around $7 at DigiKey. However, it's a nice small package (this was important for my design) and works great. You didn't say what programming language you're using, but if it's C, then WinAVR drivers have already been posted a while back.

Dave

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

Digi-Key lists the commercial temperature range MAX31000 as $ 7, while the industrial temperature range chip is $ 9. Why not use an ATmega48 which is only $2.58 or $ 2.69 and industrial temperature rated.

The ATmega48 will allow you to use any SPI mode, or TWI, or custom parallel interface. If suitable, it can even pre-process some of the serial data making it a smart peripheral. You could even add a software USART since it will not impact the main processor. The only thing I'm not sure of is how the AVR compares to the Maxim 10 microamp shutdown current with wake on serial Rx ability.

The AVR is a little more work, but its less expensive and much more flexible.

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

Not sure what your communication rates are going to be, but perhaps you could write form of slave/master protocol where only 1 serial i/o is being used at once? (Similar to multiplexing)

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

All of your replies have been considered and I am still undecided on a solution.

Quote:
Not sure what your communication rates are going to be, but perhaps you could write form of slave/master protocol where only 1 serial i/o is being used at once? (Similar to multiplexing)

The baud rate for these ports will be 9600 or 19200, but not a mixture. I like this idea hollywood21, tell me more.
1. I have considered using a uController to do the switching, not to actually replace the USART. Also, I don't want to tie up the SPI port. I am using it for other things.
2. I also consider a MAX3100 to costly for this product and ties up the SPI.
3. Basically, the MEGA128 will be the Master. It will always control the switching of which 'Slave' is spoken to or heard from. So, there needs to be 1 additional line from the slave to signal when it needs to speak. Then the Master will respond, some how, if the port is clear or not respond if the port is busy. The slave will then wait a time period to try again. This is some what how i2c does it. I haven't tried this, but should work. If there is only 1 additional line it would have to be bi-directional. So, I couldn't put it thru the RS232 chip. The old way of doing this was with hardware hand shaking. If anyone knows how this was done, maybe that will be the solution.

Again, thanks to everyone who replied. Happy Holidays :)

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

If you have control over how the slaves are set up (and it sounds like you do), I'd put all the slaves on one line. First preference would be RS485, but RS422 or RS232 could work as well.

For "alert" from the slaves, either do something in the protocol, or use extra handshake as you have been discussion.

In my last design of this type, having the slaves bid for the line caused so much complexity (if they aren't smart about it, they can blast any ongoing poll or response) that I just have the master poll fast. A round-trip to each slave: "Got anything? Nope." is about a millisecond, so I'm still getting less than 10ms. response with 8 slaves. My rough calculations of line bidding came out about the same, and is much more complex to implement.

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

Quote:
Basically, the MEGA128 will be the Master. It will always control the switching of which 'Slave' is spoken to or heard from. So, there needs to be 1 additional line from the slave to signal when it needs to speak. Then the Master will respond, some how, if the port is clear or not respond if the port is busy. The slave will then wait a time period to try again. This is some what how i2c does it.

Yup. This is what I had in mind. I'm trying to remembed exactly how it all goes to help you out, but it may have to wait until I get home. I'm at work right now and m/c comminication protocols are being screamed down by a big pile of contracts on my desk !!

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

Maybe you'd like to do some research yourself into this topic. What I had in mind is whats called a "multidrop" configuration.

This is where a number of m/c UARTs hang on the same bus with common recieve from the master and common slave lines. Each slave is individually addressed by the master to initiate transmit to avoid contention problems.

So, a message consists of a number of bytes with the first byte containing the addressing and/or control information. The address is to identify the indended reciepiant of the msg (so information may not be direct to a peer m/c)

I could talk about this in further detail but I'll let read up on it and decide if thats what you were thinking of.

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

Don't forget to include some type of data verification for the addresses and data (CRC, parity or something). It increases the overall reliability if mangled address and data are detected as such and dealt with accordingly. Otherwise, there can be unexpected communications activity and problems if data gets mangled.