8051 Tutorial 5: 8051 UART Programming in C

Filed in 8051 Microcontroller , Tutorials 1 comments

What is UART?

UART stands for Universal Asynchronous Receiver/Transmitter. As its name implies, it is universal. It can be used to establish a communication between a microcontroller and another device – microcontroller, USB controller, Bluetooth modules, GSM modules, GPS modules, personal computers, etc.

I am not going to discuss the UART protocol here. If UART is still unknown to you, you may read this article from wikipedia first.

What is RS-232?

RS-232 is a standard for serial transmission of data between a DTE (Data Terminal Equipment) and a DCE (Data Circuit-terminating Equipment). It is commonly found in desktop computers where it is commonly referred as COM port. You can read this wikipedia article for more info about the RS-232 standard.

AT89C2051 UART

The AT89C2051 has one UART port. Its TXD (Transmit) pin is the same as its P3.1 pin. Its RXD (Receive) pin is the same as its P3.0 pin.

AT89C2051 RS-232 Interface

The UART port of a microcontroller can be used to interface to a RS-232 port of a personal computer. However, the voltage levels of UART must be converted to voltage levels compatible to RS-232.

To convert UART voltage levels to RS-232 voltage levels, you may use the following circuits:

1. Using a MAX232 or similar IC

ttl-rs232-max232

This is the most preferred circuit to convert UART using the TTL voltage levels to RS232 voltage levels. The 5V levels are converted by MAX232 to -9V to -12V and vice versa. The 0V levels are converted by MAX232 to +9V to +12V and vice versa.

The female DB-9 connector is used to connect with the RS-232 port of a personal computer.

2. Using Transistors

ttl-rs232-transistor

 

This circuit is preferred by budget conscious individuals. The transistors serve as inverters. The NPN transistor converts negative voltage levels to +VCC  and positive voltage levels to 0V. The PNP transistor converts the +logic level from the TXD pin of a MCU (equal to VCC) to 0V and the 0V level from the MCU to +VCC.

Please note that the circuits above are used to convert UART lines with 0-5V levels to RS232 voltage levels. This means that the circuits above should be used to interface a microcontroller to a device with RS-232 port (personal computers). Other devices with UART ports such as GSM modules, GPS modules, Bluetooth modules, RF modules, etc does not require the RS-232 to UART converters. These devices can be interfaced to MCUs directly (as long as voltage levels for both ends are compatible with each other).

Posted by kuya   @   1 November 2009 1 comments
Tags : , , , , ,

Share This Post

RSS Digg Twitter StumbleUpon Delicious Technorati

1 Comments

Comments
Trackbacks to this post.
Leave a Comment

Name

Email

Website

Previous Post
«
Next Post
»
Zionn designed by ZENVERSE | In conjunction with Reseller Hosting from the #1 Web Hosting Provider - HostNexus | Premium Wordpress themes.