Experiment 1 UART and RS232C Standard: Objectives

Download as pdf or txt
Download as pdf or txt
You are on page 1of 8

EXPERIMENT 1

UART and RS232C Standard

Objectives

 To understand RS232-C standard and UART functions.


 To study RS232-C cabling scheme.
 To test RS232-C cable using Windows inbuilt utility.

Concept

In most cases, any device you connect to the serial port will need the serial transmission
converted back to parallel so that it can be used. This can be done using a UART. On
software side, there are many more registers that you have to attend to than on a Standard
Parallel Port. (SPP)

What are the advantages of using serial data transfer rather than parallel?

 Serial Cables can be longer than Parallel cables. The serial port transmits a '1' as -3 to -25
volts and a '0' as +3 to +25 volts where as a parallel port transmits a '0' as 0v and a '1' as 5v.
Therefore the serial port can have a maximum swing of 50V compared to the parallel port
which has a maximum swing of 5 Volts. Therefore cable loss is not as much of a problem
for serial cables then they are for parallel.
 You don't need as many wires then parallel transmission. If your device needs to be mounted
a far distance away from the computer then 3 core cable (Null Modem Configuration) is
going to be cheaper that running 19 or 25 core cable. However you must take into account
the cost of the interfacing at each end.
 Many electronic diaries and palmtop computers have infra red capabilities build in. Serial
transmission is used where one bit is sent at a time. IrDA-1 (The first infra red
specifications) was capable of 115.2k baud and was interfaced into a UART. The pulse
length however was cut down to 3/16th of an RS 232 bit length to conserve power
considering these devices are mainly used on diaries, laptops and palmtops.
 Serial Communication reduces the pin count of Microcontrollers. Only two pins are
commonly used, Transmit Data (TXD) and Receive Data (RXD) compared with at least 8
pins if you use an 8 bit Parallel method (You may also require a Strobe).

Hardware Properties

Devices which use serial cables for their communication are split into two categories. These
are DCE (Data Communications Equipment) and DTE (Data Terminal Equipment.) Data
Communications Equipments are devices such as your modem, TA adapter, plotter etc while
Data Terminal Equipment is your Computer or Terminal

The electrical specifications of the serial port are contained in the RS232C standard. It states
many parameters such as –

1. A "Space" (logic 0) will be between +3 and +25 Volts.


2. A "Mark" (Logic 1) will be between -3 and -25 Volts
3. The region between +3 and -3 volts is undefined.
4. An open circuit voltage should never exceed 25 volts. (In Reference
to GND)
5. A short circuit current should not exceed 500mA. The driver should
be able to handle this without damage. (Take note of this one!)

The RS 232 C standard specifies a maximum baud rate of 20,000 BPS. Serial Ports come in
two "sizes". There are the D-Type 25 pin connector and the D-Type 9 pin connector both of
which are male on the back of the PC, thus you will require a female connector on your
device. Below is a table of pin connections for the 9 pin and 25 pin D-Type connectors.

Serial Pin outs (D25 and D9 Connectors)

D-Type-25 Pin No. D-Type-9 Pin No. Abbreviation Full Name


Pin 2 Pin 3 TD Transmit Data
Pin 3 Pin 2 RD Receive Data
Pin 4 Pin 7 RTS Request To Send
Pin 5 Pin 8 CTS Clear To Send
Pin 6 Pin 6 DSR Data Set Ready
Pin 7 Pin 5 SG Signal Ground
Pin 8 Pin 1 CD Carrier Detect
Pin 20 Pin 4 DTR Data Terminal Ready
Pin 22 Pin 9 RI Ring Indicator

Pin Functions

Abbreviation Full Name Function


TD Transmit Data Serial Data Output (TXD)
RD Receive Data Serial Data Input (RXD)
CTS Clear to Send This line indicates that the Modem is ready to exchange data.
DCD Data Carrier Detect When the modem detects a "Carrier" from the modem at the
other end of the phone line, this Line becomes active.
DSR Data Set Ready This tells the UART that the modem is ready to establish a
link.
DTR Data Terminal Ready This is the opposite of DSR. This tells the Modem that the
UART is ready to link.
RTS Request To Send This line informs the Modem that the UART is ready to
exchange data.
RI Ring Indicator Goes active when modem detects a ringing signal from the
PSTN.

Null Modems

A Null Modem is used to connect two DTE's together without using intermediate DCEs..

9D to 25D Conversion
The UART (8250 and Compatibles)

UART stands for Universal Asynchronous Receiver / Transmitter. UART 8250 is the device
that controls the serial port. Most cards will have the UART's integrated into other chips
which may also control your parallel port, games port, floppy or hard disk drives and are
typically surface mount devices. The 8250 series, which includes the 16450, 16550, 16650,
& 16750 UARTS are the most commonly found type in your PC.

All the UARTs pins are TTL compatible. That includes TD, RD, RI, DCD, DSR, CTS, DTR
and RTS which all interface into your serial plug, typically a D-type connector. Therefore RS
232 Level Converters are used.

The UART requires a Clock to run. If you look at your serial card a common crystal found is
either a 1.8432 MHZ or an 18.432 MHZ Crystal. This clock will be used for the
Programmable Baud Rate Generator which directly interfaces into the transmit timing
circuits but not directly into the receiver timing circuits. For this an external connection mast
be made from pin 15 (Baud Out) to pin 9 (Receiver clock in.) Note that the clock signal will
be at Baud rate * 16.

Serial Port's Registers (PC's)


Port Addresses & Iraq’s

Name Address IRQ


COM 1 3F8 4
COM 2 2F8 3
COM 3 3E8 4
COM 4 2E8 3

Registers

RBR, THR, IER, IIR, FCR, LCR, MCR, LSR, MSR, SCR, DLL, DLM
The communication between the processor and the UART is completely controlled by twelve
registers. These registers can be read or written to check and change the behavior of the
communication device. Each register is eight bits wide. On a PC compatible, the registers are
accessible in the I/O port map.

RBR: Receiver buffer register (RO)

The receiver buffer register contains the byte received if no FIFO is used, or the oldest
unread byte with Fife’s. If FIFO buffering is used, each new read action of the register will
yield the next byte, until no more bytes are present. Bit 0 in the line status register can be
used to check if all received bytes have been read. This bit will change to zero if no more
bytes are present.

THR: Transmitter holding register (WO)

The transmitter holding register is used to buffer outgoing characters. If no FIFO buffering
is used, only one character can be stored. Otherwise the amount of characters depends on
the type of UART. Bit 5 in the line status register can be used to check if new information
must be written to the transmitter holding register. The value 1 indicates that the register is
empty. If FIFO buffering is used, more than one character can be written to the transmitter
holding register when the bit signals an empty state. There is no indication of the amount of
bytes currently present in the transmitter FIFO.

The transmitter holding register is not used to transfer the data directly. The byte is first
transferred to a shift register where the information is broken in single bits which are sent
one by one.

LCR: Line control registers (R/W)

The line control register is used at initialization to set the communication parameters.
Parity and number of data bits can be changed for example. The register also controls the
accessibility of the DLL and DLM registers. Because they are only accessed at
initialization when no communication occurs this register swapping has no influence on
performance.
LCR:Line Control Register

Bit Value Detail

0,1 Bit 1 Bit 0 Data Word Length

0 0 5 Bits

0 1 6 Bits

1 0 7 Bits

1 1 8 Bits

2 0 1 stop bit

1 1.5 stop bits(5 bits word)


2 stop bits (6,7 or 8 bit word)
3,4,5 Bit 5 Bit 4 Bit 3

X X 0 No parity

0 0 1 Odd Parity

0 1 1 Even Parity

1 0 1 High Parity(stick)

1 1 1 Low Parity(stick)

6 0 Break signal disabled

1 Break signal enabled

7 0 DLAB : RBR, THR and IER accessible

1 DLAB : DLL and DLM accessible

Common settings are:

8 data bits, one stop bit, no parity


7 data bits, one stop bit, even parity

LSR : Line status register (RO)


The line status register shows the current state of communication. Errors are reflected in
this register. The state of the receiver and transmitter buffers is also available.

LSR : Line status register

Bit Comment

0 Data available

1 Overrun error

2 Parity error

3 Framing error

4 Break signal received

5 THR is empty

6 THR is empty, and line is idle

7 Erroneous data in FIFO

Bit 5 and 6 both show the state of the transmitting cycle. The difference is, that bit 5 turns
high as soon as the transmitter holding register is empty whereas bit 6 indicates that also
the shift register which outputs the bits on the line is empty

DLL and DLM : Divisor latch registers (R/W)

The frequency (1.8432 MHz) is divided by 16 to generate the time base for
communication. Because of this division, the maximum allowed communication speed is
115200 bps. Modern UARTS like the 16550 are capable of handling higher input
frequencies up to 24 MHz which makes it possible to communicate with a maximum speed
of 1.5 Mbps. This 115200 bps communication speed is not suitable for all applications. To
change the communication speed, the frequency can be further decreased by dividing it by
a programmable value. For very slow communications, this value can go beyond 255.
Therefore, the divisor is stored in two separate bytes, the DLL and DLM which contain the
least, and most significant byte.

It is necessary that both the transmitting and receiving UART use the same time base.
Default values have been defined which are commonly used. The table shows the most
common values with the appropriate settings of the divisor latch bytes.

DLL and DLM : Divisor latch registers


Speed(bps) Divisor DLL DLM

50 2304 0x00 0x09

300 384 0x80 0x01

1200 96 0x60 0x00

2400 48 0x30 0x00

4800 24 0x18 0x00

9600 12 0x0C 0x00

19200 6 0x06 0x00

38400 3 0x03 0x00

57600 2 0x02 0x00

115200 1 0x01 0x00

You might also like