Society of Robots - Robot Forum

Electronics => Electronics => Topic started by: robotmaniac on July 22, 2013, 12:01:15 PM

Title: UART conections
Post by: robotmaniac on July 22, 2013, 12:01:15 PM
hey guys I wanted to add UART function to my Atmega8 form the $50 robot, but I was wondering If i could, open a usb and connect the usb's tx and rx directly to my atmega8...But I saw the UART  tutorial and there was this CP2102, but for what use this thing? Cant i just go form my usb to the atmega8?

The USB has data (+) and data (-)... which one is RX and TX???
Title: Re: UART conections
Post by: johnwarfin on July 22, 2013, 02:05:34 PM
it is possible to connect m8 directly to usb but the circuit and software are very complicated. better to use a usb2serial dongle like this:

http://www.ebay.com/itm/USB-To-RS232-TTL-Auto-Converter-Module-Converter-Adapter-For-Arduino-S9-F8s-/370859426819?pt=LH_DefaultDomain_0&hash=item5658f1c403#ht_4376wt_1056 (http://www.ebay.com/itm/USB-To-RS232-TTL-Auto-Converter-Module-Converter-Adapter-For-Arduino-S9-F8s-/370859426819?pt=LH_DefaultDomain_0&hash=item5658f1c403#ht_4376wt_1056)

they only cost a buck or so and will allow interfacing many different serial projects.
Title: Re: UART conections
Post by: robotmaniac on July 22, 2013, 04:27:00 PM
hey, thanks but what about using a usb cable used for cellphones... I mean, cellphones have microcontrollers of some sort so wouldnt that usb have a thing for communicating the computer with the cellphone? ?
and sorry for my english, I am from Puerto Rico...
Title: Re: UART conections
Post by: jwatte on July 22, 2013, 04:30:23 PM
hey guys I wanted to add UART function to my Atmega8 form the $50 robot, but I was wondering If i could, open a usb and connect the usb's tx and rx directly to my atmega8...But I saw the UART  tutorial and there was this CP2102, but for what use this thing? Cant i just go form my usb to the atmega8?

The USB has data (+) and data (-)... which one is RX and TX???

The Atmega8 does not support USB. The TX/RX on the Atmega8 speak "UART" protocol. Meanwhile, the D+ and D- on a USB port speak "USB NRZ" protocol. They are not compatible.
There is a version of the Atmega8 called the Atmega8u2 which does support USB, but unfortunately, it's not available in DIP package, only in surface-mount package, so it's going to be very hard to work with if you don't know how to do reflow soldering in an oven.
Title: Re: UART conections
Post by: robotmaniac on July 22, 2013, 04:40:22 PM
 :o OK, thanks buddy... I will buy the USB2serial dongle... I don't need anything else for the UART right?? Already have Hyper-terminal...
Title: Re: UART conections
Post by: waltr on July 22, 2013, 05:49:06 PM
First look up UART, asynchronous serial, RS232 and USB in Wiki to learn about these.
Second, there are a few Async Serial (UART) to USB adapters. These use a chip that converts between the two protocols and are fairly easy to use.
Adafruit and SparkFun both sell them that go for your USB port directly to your Atmega UART pins.

Other adapters go from USB to RS232 which then means you need an RS232 to TTL level translation chip, like a MAX232.
Title: Re: UART conections
Post by: robotmaniac on July 22, 2013, 07:11:47 PM
ok, thank you guys :)
Title: Re: UART conections
Post by: robotmaniac on July 22, 2013, 07:34:45 PM
would this one do the job without any extra hardware?
http://www.ebay.com/itm/1pcs-New-USB-2-0-to-TTL-UART-Module-5pin-Serial-Converter-CP2102-STC-5pin-cables-/400524483249?pt=LH_DefaultDomain_0&hash=item5d411e9ab1 (http://www.ebay.com/itm/1pcs-New-USB-2-0-to-TTL-UART-Module-5pin-Serial-Converter-CP2102-STC-5pin-cables-/400524483249?pt=LH_DefaultDomain_0&hash=item5d411e9ab1)
Title: Re: UART conections
Post by: johnwarfin on July 23, 2013, 06:24:57 AM
yes, other than costing 4x more than the one in the link i gave you it will work fine. all you need is hyperterm and the software driver which is easy to download.
Title: Re: UART conections
Post by: robotmaniac on July 23, 2013, 12:08:47 PM
Haha, but the one you gave me is from USB to rs232 right? So I would need for example a max232?
Title: Re: UART conections
Post by: jwatte on July 24, 2013, 10:29:21 AM
RS232 is a high-voltage dual-voltage signaling scheme (typically -12V for 1 and +12V for 0.)
The USB adapter shown is to TTL levels (which means 5V) where +5V is 1 and 0V is 0.
The TTL version is what you need for any on-board UART connections. The Max232 chip is only needed if you actually need to talk to RS232 specific equipment through RS232 connectors (typically DB-25, or DB-9 form factor.)
It is a little confusing that, sometimes, people will say "RS232" when they really mean "asynchronous serial." The key in the product listing is that it says "TTL" in the title. (There is no such thing as "RS232 TTL" but there is "TTL-level asynchronous serial.") Additionally, generating RS232 signals from an USB bus powered device is somewhat complex, and requires more hardware than can be seen on that dongle, and would also significantly increase the price.
Title: Re: UART conections
Post by: johnwarfin on July 24, 2013, 11:04:39 AM
Haha, but the one you gave me is from USB to rs232 right? So I would need for example a max232?

nope. virtually all these little pcb dongles are active low signal which is what the mcu needs. although commonly called "ttl" or "5v", this is a big mistake because level has nothing to do with it. original rs232 worked fine with ttl/5v. it is polarity that matters and creates 99% of the confusion for those starting out.

old pc rs232 was active high (+9v, +12v, etc) but modern serial is overwhelmingly reversed to active low (0v). voltage never really matters. its polarity and baud that count.
Title: Re: UART conections
Post by: waltr on July 24, 2013, 11:51:12 AM
All of this is why I suggested to:
Quote
First look up UART, asynchronous serial, RS232 and USB in Wiki to learn about these.
Else is does get confusing especially when some one advertizes some thing that is "RS232 TTL" which jwatt commented on correctly.
Title: Re: UART conections
Post by: jwatte on July 25, 2013, 09:51:14 AM
Quote
old pc rs232 was active high (+9v, +12v, etc) but modern serial is overwhelmingly reversed to active low (0v).

What's extra confusing is that what you call "active" here is actually the "0" value for a bit. The TTL asynchronous serial devices all pull the line up to 5V while idle. Then, the "start bit" is a zero, so it will pull the line low to indicate the byte that's coming, then the logic level is normal (5V == 1, 0V == 0) for each bit, then the stop bit is high, which returns the line to "idle" 5V state.

Meanwhile, RS232 defines the negative voltage as the "1" state, and the positive voltage as the "0" state. What you call "active" would be less confusingly called "logical 0" IMO.
Title: Re: UART conections
Post by: johnwarfin on July 25, 2013, 07:15:07 PM
in electrical engineering active low refers to input and output pin voltage and has nothing to do with binary software states. if it performs a function when 0v or negative its "active low". otherwise "active high". if those terms bother you then "idle high" and "idle low" are acceptable, but less common, alternatives. "logical 0" or "logical 1" is more appropriate for describing boolean operations and other internal software states. in any case with modern pc async and nearly all mcu uarts active low IS logic zero.

its true that polarity results in some confusion for beginners but nowhere near as bad as referring to "level" (ttl or otherwise) which has little to do with most serial problems.