ATmega8 USART Question.

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

I'm a newbie to MCU's. With an ATmega8, or any other MCU with a ASART/UART for that matter, is it possible to connect and 'talk' to more than one device at a time through the USART? I want to connect an RF data transmitter and another data collection device, both designed to connect to a USART.

I want to trigger the collection device, it will do its thing and give a result to the mega8, which will then RF transmit commands to another MCU which will execute the commands.

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

The UART protocol used by both devices needs either some way of distinguishing messages (address scheme) or a form of chip select to allow one to be used at a time.

If thats not an option, and you can guarantee that the device simply responds to requests and doesn't transmit on its own, you can use an output enable buffer to each device, which would isolate the UART traffic from one device to another.

If thats not an option, you need two UARTs :).

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

If the speeds aren't too high, and particularly if the RF device doesn't send anything back, then writing a software UART for it is another option.

Chuck Baird

"I wish I were dumber so I could be more certain about my opinions. It looks fun." -- Scott Adams

http://www.cbaird.org

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

Or you could switch the TX/RX pins between the two devices, if they do not require simultaneous communication.

Use a digital or analog mux. A digital multiplexer can be done with discrete logic gates too.

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

The RF transmitter is a Sparkfun 315Mhz, WRL 08945, and as far as I can tell it will have no address and will not send anything back to the MCU. The other device is a SRF02 ultrasonic ranger module, which requires address and command bytes to do anything.

Basically I want to Ping the rangefinder, wait, then retrieve it's result, analyze the result, and send commands to another mega8 via the RF transmitter, then loop back continuously.

It would seem that I cannot do both from the usart ports, since anything I output there for the rangefinder would also be RF transmitted. But I think it would just be ignored at the reciever MCU, correct?
If this is true, all I need to do is time it correctly, I think, and make sure to use start and stop bits or whatever the case for the data I DO want to RF transmit. Is this logical?

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

With that transmitter (one way communications, 2400 or 4800 baud) I'd just use a software UART. It would be pretty easy to do using a timer interrupt, since it doesn't look like you're going to be short on resources.

Chuck Baird

"I wish I were dumber so I could be more certain about my opinions. It looks fun." -- Scott Adams

http://www.cbaird.org

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

Thanks, zbaird. No, I'm not short on resources, just code smarts. I study alot, 2,3 hours a day, but like I said, I'm new to programming.

Problem is, I don't know what software uart you are refering to. This project is a stand-alone thing. Can I program a mega8 i/o for this separate from its usart?

I guess what I'm looking foris some guidence toward what I need to learn to make this happen, and any direction I get is very much appreciated. I'm learning Cpp, but on my own with online tutorials. I'm getting it, but I'm not a software engineer, I'm an electronics eng., who's always had bad things to say about you guys. The shoe is on the other foot, though, and at this point I take it all back!

I do understand interupts, though, so could you kindly outline how I can do this?

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

There's an application note that talks about how to do this. Have a look at it and see if it makes sense. You can ignore all the receiver stuff, since you only need a transmitter.

Chuck Baird

"I wish I were dumber so I could be more certain about my opinions. It looks fun." -- Scott Adams

http://www.cbaird.org

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

Maybe pick one of chips that has 2 usuart's (mega162 for instance) if you haven't already settled on a mega8 .

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

Logic gates are cheap and easy.. We did something like this last year and used a multiplexer and a demultiplexer. We were using an atmega164p which has two sets of USARTs but we needed 4 so the mux/demux did the job.

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

Looking at the spec for the srf02 it says it has both async and i2c interfaces. There's plenty of example i2c code that you can adapt so that frees up the uart for the rf stuff. problem solved.

Also, these cheapy modules sorta work when feeding the via a uart but its not the best way. Many people have found this out the hard way. All the commercial units that I've seen that use these simple modules use a specific encoding scheme such as a infrared remote control protocol or manchester encoding. Either of these don't use the uart.

so again, the issue of sharing the uart has been resolved.