Experiment 1 UART and RS232C Standard: Objectives
Experiment 1 UART and RS232C Standard: Objectives
Experiment 1 UART and RS232C Standard: Objectives
Objectives
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 –
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.
Pin Functions
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.
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.
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.
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.
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
0 0 5 Bits
0 1 6 Bits
1 0 7 Bits
1 1 8 Bits
2 0 1 stop bit
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)
Bit Comment
0 Data available
1 Overrun error
2 Parity error
3 Framing error
5 THR is empty
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
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.