ATMega8 1 USART for 2 "Consumers"

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

Hello

 

My ATMega8 has got only 1 USART however I'd like to hook up 2 "consumers" - one XBEE Module (to communicate with a 2nd ATMega via XBEE) and a line to my computer to show the contents of the transferred data via hTerm.

 

Is it possible to have 2 "consumers" on one USART or poses this some kind of "overload" to the USART?

 

best regards

 

Hero_123

 

 

This topic has a solution.
Last Edited: Thu. Sep 12, 2019 - 05:03 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

It's quite tricky to multiplex a UART. You have a couple of options:

 

1) implement one of the UARTs as a "soft UART" - that is a UART that is "faked" by simply switching pins on/off form time to time. It's very easy to do the transmission side of a UART this way but more complex to do the receive side so if one channel is only or mainly output only then do that one as soft UART

 

2) a much better idea is to use an AVR that has 2 or more UARTs. For example the 40 pin mega164P/mega324P/mega644P/mega1284P range have two.

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

Hero_123 wrote:
Is it possible to have 2 "consumers" on one USART

You mean like this:


                   +--------+                    +--------+
                   | UART 1 |                    | UART 2 |
                   |   Rx   |                    |   Rx   |
                   +---+----+                    +---+----+
                       ^                             ^
                       |                             |
+---------+            |                             |
|         |            |                             |
| UART Tx +------------+-----------------------------+
|         |
+---------+

 

Yes, of course that's possible - but it means that both "consumer" UARTs will receive everything.

 

If that's OK in your application, then problem solved!

 

laugh

 

Otherwise, as clawson says, you could either multiplex the "consumers", or add a soft UART in your AVR.

 

But, by far the best solution is:

clawson wrote:
use an AVR that has 2 or more UARTs

it's not like they are rare or difficult to obtain these days!

 

(edited)

 

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
Last Edited: Thu. Sep 12, 2019 - 10:56 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

An Atmega808 costs $0.76 (for one) and has three UARTs in a 32 pin package (so it has to be SMD)

Last Edited: Thu. Sep 12, 2019 - 12:50 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Yes it is very easy to do with one sender and two receivers, just connect the TXD pin of the AVR to the RXD pin(s) of the two receivers and of course they also need a common GND.

This does ASSUME all three units are TTL level comms!

 

Jim

 

Click Link: Get Free Stock: Retire early! PM for strategy

share.robinhood.com/jamesc3274
get $5 free gold/silver https://www.onegold.com/join/713...

 

 

 

 

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

ki0bk wrote:
of course they also need a common GND

Indeed.

 

It was implied in my original diagram so, to be explicit:

                   +--------+                    +--------+
                   | UART 1 |                    | UART 2 |
                   | Rx GND |                    | Rx GND |
                   +-+---+--+                    +-+---+--+
                     ^   |                         ^   |
                     |   |                         |   |
+---------+          |   |                         |   |
|         |          |   |                         |   |
| UART Tx +----------+-----------------------------+   |
|         |              |                             |
+----+----+              |                             |
     |                   |                             |
     |                   |                             |
=====+===================+=============================+== GND

 

 

 

This does ASSUME all three units are TTL level comms!

or add appropriate level shifters as required

 

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Andy, how do you make your ascii drawings?

 

Click Link: Get Free Stock: Retire early! PM for strategy

share.robinhood.com/jamesc3274
get $5 free gold/silver https://www.onegold.com/join/713...

 

 

 

 

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

That one was just by laborious use of the spacebar, '+', '-', etc, keys in the forum's code editor.

With a lot of copy & paste.

 

Otherwise, I use a text editor.

I find CodeWright is good for this, as it puts in all the leading spaces for you when you type a character "in mid air".

 

I guess another option would be to fill a page with spaces, and use overtype ...

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

That's how I have done it, lots of work.

 

Click Link: Get Free Stock: Retire early! PM for strategy

share.robinhood.com/jamesc3274
get $5 free gold/silver https://www.onegold.com/join/713...

 

 

 

 

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

Google is your friend folks....

            Cliff drew all this in about 1 minute....

+--------------------------------+        A pointy straight line
|                                +------------+
|                                |            |
|                                |            |
|        This is Box 1           |            |
|                                |            v
|                      +----------------------+----------+
|                      |         |                       |
|                      |         |                       |
+---X----------------------------+                       |
 XXX                   |                                 |
XX                     |       This is box 2             |
XX              XXXX   |                                 |
 XXX          XX   XXXXX                                 |
   XXXXXXXXXXX         |                                 |
                       +---------------------------------+
A wiggly wire

:-)

 

£5 buys you the URL devil

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

 

OK, I'm not that mean - this looks like a lot of fun...

 

Hopefully the tool bar items are obvious when you are done use the one that looks like:

 

        ^
        |
+-----  |   ------+
|       |         |
|       +         |
|                 |
|                 |
|                 |
+-----------------+

(do you see what I did there? ;-)

 

That gives "Export" and the diagram appears in a box where you can copy it from and paste it here.

 

Last Edited: Thu. Sep 12, 2019 - 02:34 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The XBEE modules use 3v3 logic levels so BE CAREFUL or you WILL blow the pins....

 

If yu are doing simple "Talk to the XBEE, then transfer the data to the PC then it is certainly very simple to use a multiplexer IC and some additional pins from the AVR to steer the data.  NO need for anything else.  BUT, you need to use buffers for storing the data from each consumer in the AVR while you set up the steering logic.

 

 

Just keep in mind the XBEE is 3v3 and its NOT forgiving.

Jim

I would rather attempt something great and fail, than attempt nothing and succeed - Fortune Cookie

 

"The critical shortage here is not stuff, but time." - Johan Ekdahl

 

"Step N is required before you can do step N+1!" - ka7ehk

 

"If you want a career with a known path - become an undertaker. Dead people don't sue!" - Kartman

"Why is there a "Highway to Hell" and only a "Stairway to Heaven"? A prediction of the expected traffic load?"  - Lee "theusch"

 

Speak sweetly. It makes your words easier to digest when at a later date you have to eat them ;-)  - Source Unknown

Please Read: Code-of-Conduct

Atmel Studio6.2/AS7, DipTrace, Quartus, MPLAB, RSLogix user

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

clawson wrote:
Google is your friend 

LOL - the first suggestion as I type "asciiflow" into Google is, "asciiflow alternatives"

 

laugh

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
This reply has been marked as the solution. 
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hello clawson, hello awneil, hello ki0bk, hello jgmdesign

 

Thanks a lot for your fast answers yessmiley

 

My idea was to exchange data between those 2 ATMega8 via USART and XBEE (both transmit & receive data) and my PC is hooked up to one USART (in parallel to one XBEE) to "listen" to the transmitted data of that ATMega8; both ATMega share the same powersupply.

 

@clawson - yeah, best would be using two seperate usarts on each ATMega however I can only use either ATMega8 or ATMega168 or ATMega328 as both are sitting on hard wired boards with an 28-pin socket(need ATMega with 14 pins each side).
So one option were a "soft usart"; another possibility were that "multiplexing" solution.
A third option - I have already established a SPI communication between those 2 ATMega8 and I could switch one to "Receive" and the other to "Transmit" via SPI command and vice versa.

 

@awneil - your picture - great!! Did help me a great deal! So it's no problem to have my XBEE and my PC hooked up to the same USART.

 

@jgmdesign - yeah, thanks for that advice; my XBEEs are sitting on boards with a level converter 5V -> 3.3V.
"Steering logic" with multiplex IC - good idea! My send/receive data are stored in a buffer (small one, though).

 

best regards

Hero_123

 

 

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

Hero_123 wrote:
my PC is hooked up to one USART (in parallel to one XBEE) to "listen" to the transmitted data of that ATMega8

Yes, there is no problem at all to do that (paying attention to voltage levels, of course) - it's a standard approach:

 

Of course, if you want to see "both sides" of the communication (what the AVR sends to the XBee, and what the XBee sends back to the AVR), you need two terminals:

 

https://www.avrfreaks.net/comment/2306116#comment-2306116

 

https://www.avrfreaks.net/commen...

 

 

best would be using two seperate usarts

When you're actually wanting to watch the comms between the 2 devices, you would not use a separate UART.

 

The advantage of having a separate UART is that it can send debug information other than the comms between the 2 parts.

 

It was not clear from your OP what you were actually asking.

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hello awneil

 

Thanks a lot for your answer smiley

 

Sorry that I wasn't clear enough in my OP - my fault - it's a bit tricky to properly ask a technical question when not being a native speaker frown (it's sometimes also tricky even WHEN being a native speaker).

 

best regards

 

Hero_123

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

Hero_123 wrote:
a bit tricky to properly ask a technical question when not being a native speaker

That's true.

 

Often a diagram helps ...

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hello awneil

 

awneil wrote:
Often a diagram helps .

 

That thought occured to me just a few minutes ago, too - next time I do know better wink

 

best regards

 

Hero_123

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

Hero_123 wrote:
next time I do know better

And you can have a go with that clever ASCII-art app that clawson found!

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hello awneil

 

awneil wrote:

And you can have a go with that clever ASCII-art app that clawson found!

 

yeswink

 

best regards

 

Hero_123