Professional Documents
Culture Documents
Page 1
Contents
Introduction
PC Serial Port
RS-232 Protocol
Theory of Operation
Setting UART in micro-controller
Hyper Terminal
Page 2
Introduction:
There are many ways to interface your microcontroller to computer. The
easiest way is to use UART i.e. Universal Asynchronous Receiver
Transmitter. It is a way of communication between the microcontroller and
the computer system or another microcontroller.
Data exchange can be done using serial or parallel techniques. In parallel
communication, the complete byte of data is sent at one time with each bit
having a separated dedicated data line. This method is very fast but not
cost effective. On the other hand serial communication is somewhat slower
as every bit of data is sent serially one by one but is cost effective as only
two data lines i.e. transmitter and receiver lines are required (of course a
ground line is also required in addition to these two). Serial data
communication can be further divided into two categories - synchronous
and asynchronous. In synchronous communication transmitter and
receiver are synchronised by a clock whereas in asynchronous system no
clock pulse is shared between receiver and transmitter. As the name
suggests UART is an example of asynchronous communication. Since no
common clock is shared, a known data transfer rate (baud rate) must be
agreed upon prior to data transmission i.e. the receiving UART needs to
know the transmitting UARTs baud rate (and conversely the transmitter
needs to know the receivers baud rate).
Page 3
Page 4
RS-232 Protocol:
The standard used for serial communication is RS-232 (Recommended
Standard 232). The standard defines voltage levels that correspond to
logical zero and logical one level. Voltages between plus and minus 3 to 15
volts are allowed voltages. Logic one is defined as a negative voltage; the
signal condition is called marking, and has the functional significance of
OFF. Logic zero is positive; the signal condition is spacing, and has the
function ON. Voltage between plus or minus 3 volts near zero are not
allowed. This is not the voltage level at which our microcontroller works.
We have two different machines with two different ways to define 0 & 1
and we want to exchange information between them. Consider
microcontroller as a French and Computer's Serial Port as an Indian person
(obviously no common language in between!). If they want to exchange
information they basically need a mediator who knows both the language.
In other words, we need a device which can convert serial ports voltage
level to that of CMOS( i.e. logic 1 = +5V and logic 0 = 0V). This task is carried
out by an IC MAX 232, which is always used with four 10uF capacitors. The
circuit is shown:
Page 5
Theory of Operation:
Figure 1.3 illustrates a basic UART data packet. While no data is being
transmitted, logic 1 must be placed in the Tx line. A data packet is
composed of 1 start bit, which is always a logic 0, followed by a
programmable number of data bits (typically between 6 to 8), an optional
parity bit, and a programmable number of stop bits (typically 1). The stop
bit must always be logic 1.
Most UART uses 8bits for data, no parity and 1 stop bit. Thus, it takes 10
bits to transmit a byte of data.
Page 6
BAUD Rate: This parameter specifies the desired baud rate (bits per
second) of the UART. Most typical standard baud rates are: 300, 1200,
2400, 9600, 19200, etc. However, any baud rate can be used. This
parameter affects both the receiver and the transmitter. The default is 2400
(bauds).
In the UART protocol, the transmitter and the receiver do not share a clock
signal. That is, a clock signal does not emanate from one UART transmitter
to the other UART receiver. Due to this reason the protocol is said to be
asynchronous.
Since no common clock is shared, a known data transfer rate (baud rate)
must be agreed upon prior to data transmission. That is, the receiving
UART needs to know the transmitting UARTs baud rate (and conversely
the transmitter needs to know the receivers baud rate, if any). In almost all
cases the receiving and transmitting baud rates are the same. The
transmitter shifts out the data starting with the LSB first.
Once the baud rate has been established (prior to initial communication),
both the transmitter and the receivers internal clock is set to the same
frequency (though not the same phase). The receiver "synchronizes" its
Electronics Engg Society
Page 7
Page 8
Page 9
You get a list of options to select from for the baud rate. Baud Rate is the
unit of data transfer, defined as bits per second. We will select 9600 as it is
fair enough for our purpose, and default setting in most of the applications
(like Matlab, Docklight, etc.). Keep the communication parameters as
default, i.e., 8 data, 1 stop and no parity and mode asynchronous. You also
have option of enabling Rx and Tx Interrupt functions. Enabling them will
Page 10
2. getchar: To receive one character from the buffer, which might have
been sent by the other uC or the computer. E.g., if we have already defined a
variable char c, then
c = getchar();
Similarly, there are functions like puts() and gets() that work on string in
similar fashion.
Hyper-Terminal:
To communicate with the computer, you need a terminal where you can
send data through keyboard and the received data can be displayed on the
screen. There are many softwares which provide such terminal, but we will
be using Hyper-terminal. Its evaluation version is free for download on
internet, which is sufficient for our purpose.
You can download the evaluation version of hyper-terminal from
http://www.hilgraeve.com/htpe/support/htpe7.exe
Page 11
Figure 1.4
In the next dialog box enter the com port on which your usb to serial
connector is working and click OK. To find out the COM port on which your
serial connector is working, check the Device Manager in System
Properties.
Note: The COM port changes every time you plug-in the connector.
Page 12
Figure 1.5
In the dialog box that appears enter the values for baud rate, character size
of uart data frame, parity bits, number of stop bits and flow control. These
values should be same as that you have configured in your microcontroller.
However, most of the systems use 9600 baud-rate, 8 data bits and no
parity. If you are also using this configuration, click RESTORE DEFAULT
button.
Page 13
Figure 1.6
Click on OK and you are ready to send and receive data over serial port.
Type anything on the keyboard and it will be transmitted over uart.
Anything received over UART will appear on the screen.
Page 14
Figure 1.7
If you have any suggestion that you would like to share with us feel free to
contact at:
akash.singh.ece10@itbhu.ac.in
Akash Singh
Electronics Engg.
IT BHU
Page 15