Lecture 6 - Serial Communications
Lecture 6 - Serial Communications
Parallel transfer
whole byte of data transferred simultaneously using separate data lines
a dedicated ground line required for each data line to reduce noise
lower voltage for transmission
UCCE2043 Basic Microprocessor example: printer ports
Interface good for slower data transfer or over long distance, e.g. mouse, modem
RS232: the most popular standard
H Y Lee
[email protected]
1 2
Eg: RS-232
Example
1=mark 0=space, transmission begins with start bit follow by the LSB and end with
1 or 2 stop bit
Start bit
0 b0 b1 … bn p s1 s 2
Asynchronous. Need of framing… Start Bit
Optional parity bit. 1-2 stop bits. ASCII
Parity Stop bit
2 stop bits is used in older systems due to slowness of the system to give it
sufficient time to organize itself before transmitting next byte.
total number of bits to be transferred is: 2 stop + 1 start +8 ASCII = 11 bits
Baud is the number of signal level changes per second in a line, regardless of the
111101000001111
information content of those signals. More in Appendix A
Idle
A
Bits per second (bps) is the rate of transfer of information bits
From the book The 80x86 IBM PC by Muhammad Ali
5 6
Mazidi and Janice Gilispie pg. 511
transmitter
RTS
RTS: Request To Send
receiver
CTS No
TD
CTS: Clear To Send Send RD
character
ON when DCE is ready to receive data
SG: Signal Ground
11 12
Electrical Characteristics UART to RS232 Connections
Single-ended
one wire per signal, voltage levels are with respect to
system common (i.e. signal ground)
Mark: 1 is represented by: -3 to -25 Converting voltage from TTL
level to RS232 level
Space: 0 is represented by: +3 to +25
-3V to +3V is undefined
Line driver (1488)
Converting voltage from TTL level To RS232 level
Line receiver (1489)
Converting voltage from RS232 level To TTL level
High speed data transfer unreliable because of the
capacitance. Converting voltage from
Recommended maximum cable length is 15m, at RS232 level to TTL level
20kbps
From the book The 80x86 IBM PC by Muhammad Ali
13 14
Mazidi and Janice Gilispie pg. 512
COM1Serial
PC/AT PortPort – 8250/16450/16550 UART
The Serial Port
16550 is a 40-pin IC with an 8-bit data bus.
UART 8250
1488, RS -232
It receives a single character from the CPU,
or 16450 or 16550
Reset
MR
Intrp
SOUT
Level Shift, Out
3, TX
9 - Pin
D - Type
frames it (insert start and stop bit), then
RTS 7, RTS
Connector
transmits it serially.
DTR 4, DTR
CTS 8, CTS and stop bits, make a character out of it, and
DSR 6, DSR
IOR
IOW
A0
DISTR
DOSTR
A0
RI 9, RI present it to the CPU.
RLSD 1, DCD
A1 A1
A2 A2
1489, RS -232 5, GND
It also generates all the necessary modem
I/O decoded
CS
XTAL1
Level Shift, In
handshake signals.
1.8432 MHz. Osc.
FG
Add Function
From the book The 80x86 IBM PC by Muhammad Ali Note: Please refer to Slide 22 and make comparison
23 24
Mazidi and Janice Gilispie pg. 523
UART Registers Interrupt Enable Register
Transmitter Holding Register - (A2 A1 A0 =000, and DLAB =0)
To transfer a byte serially, the byte must first be written to this register by the
CPU.
After a byte is written into this register, the 8250 frames it with proper start
and stop bits and transfers it serially through the Sout pin.
Receiver Buffer Register - (A2 A1 A0 =000, and DLAB =0)
When the 8250 receives the data through the Sin pin, it strips away the
framing bits, makes it a byte, and holds it in this register for the CPU to read.
Interrupt Enable Register - (A2 A1 A0 =001, and DLAB =0)
Bits D7 - D4 of this register are always 0, and the rest are used for the
hardware-based interrupt to notify the CPU of certain conditions.
While there is only one INTR pin on the 8250, there are four sources that can
activate it.
The Interrupt Enable Register is used to mask or unmask any of these
sources.
25 26
27 28
Interrupt Identification Register Priority
Interrupt Identification Register Priority
One might wonder how the CPU can know which is the source
of INTR activation if all these conditions can activate the single
INTR pin.
This is exactly the function of the Interrupt Identification Register.
This is a read-only register used to poll to determine the source
of activation of the INTR pin.
While D0 indicates if an interrupt is pending, D1 and D2 provide
the source of the interrupt with the highest priority. They are
prioritized as shown in Table (Slide 28 or 29).
Another major use of this register is its ability to implement the
polling method in monitoring INTR. The polling method first
checks D0 to see if there is an interrupt pending and if there is
one, D 1 and D2 are tested to see which one.
D3 to D7 of this register are always 0.
29 30
Solution:
We have 0000 1010 =0AH for the Line Control Register, and the program
is as follows:
MOV DX,3FBH ;the data format reg. port address
MOV AL,0AH ;DLAB =0, no brk cont, odd, 1 stop, 7 bits
OUT DX,AL ;issue it
Notice in the above example that DLAB can be 0 or 1 for the data
format register, but to access the buffer/hold register it must be 0, and
for the divisor latch it must be 1, as we will see the coming slide
Note: You may refer to Slide 22
33 34
35 36
E.g. E.g.
Program the divisor latch for 300 baud, assuming that Xin=1.8432 Program the divisor latch for 2400 baud, assuming that Xin=1.8432
MHz. Use the I/O port addresses of Slide 23. MHz. Use the I/O port address of Slide 23.
Solution: Solution:
MOV AL,80H ;10000000 (binary) to access DLAB MOV AL,80H ; 10000000 to access DLAB
MOV DX,3FBH ;the address of line control reg MOV DX,3FBH ;the address of line control reg
OUT DX,AL ;make D7 =1 for DLAB; now send the divisor value OUT DX,AL ;make D7=1 for the DLAB; now send the divisor value
MOV AX,384 ;For 300 baud rate, Divisor Value=384 (Slide 35) MOV AX,48 ;For 2400 baud rate, Divisor Value=48 (Slide 35)
MOV DX,3F8H ;divisor latch address (LSB) MOV DX,3F8H ;divisor latch address (LSB)
OUT DX,AL ;issue the low byte OUT DX,AL ;issue the low byte
MOV AL,AH ; MOV AL,AH
INC DX ;the divisor latch address (MSB) INC DX ;the divisor latch address (MSB)
OUT DX,AL ;ISSUE THE HIGH BYTE OUT DX,AL ;issue the high byte
37 38
41 42
45 46
Asynchronous
Mode
8251A Initialization
Flowchart
47 48
Mode Instruction (Synchronous Mode) 8251A USART Command Register
Answer
i) 19200/16 = 1200
ii) 19200/64=300
UPDATE 2009 51 52
E.g. E.g.
Find the I/O port address assigned to the What value must be written into the mode control
8251 if CS is activated by A7-A1= register with baud rate divided by 16, character
“1001100” and A0 is connected to C/D size 16 bits, odd parity, one stop bit. Write an
assembly program.
Answer
Answer
1001 1000 = 98H Data Register
0101 1110 = 5Eh
1001 1001 = 99H Status Register MOV AL, 0100 0000 ;RESET THE 8251 D6 OF COMMAND REG
OUT 99H,AL
MOV AL,5EH
OUT 99H,AL
53 54
Mode
instruction-
Asynchronous
E.G.
Write a program that transfer the message
“I AM CT SMART STUDENT”,”$” into the
command
Status
8251. The “$” indicate the end of the
message: Use the data format and the
baud rate of the previous example.
55 56
ANS. Appendix A: Baud Rate vs Bps
DATA DB “I AM CT SMART STUDENT”,”$” Bps is simply the number of bits transmitted per second.
MOV AL,00 The Baud Rate is a measure of how many times per
OUT 99H,AL
OUT 99H,AL
second a signal changes (or could change).
OUT 99H,AL
MOV AL, 0100 0000
For a typical serial port a 1-bit is -12 volts and a 0-bit is +12 v (volts).
OUT 99H,AL If the bps is 38,400 a sequence of 010101... would also be 38,400
MOV AL,5EH baud since the voltage shifts back and forth from positive to
OUT 99H,AL negative to positive, etc. and there are 38,400 shifts per second.
MOV SI,OFFSET DATA
BI: IN AL,99H Suppose that a "change" may have more than the two possible
AND AL,00000001B
JZ BI
outcomes of the previous example (of +- 12 v). Suppose it has 4
MOV AL,[SI] possible outcomes, each represented by a unique voltage level.
CMP AL,”$” Each level may represent a pair of bits (such as 01). For example, -
JE B2 12v could be 00, -6v 01, +6v 10 and +12v 11. Here the bit rate is
OUT 98H,AL
INC SI double the baud rate. For example, 3000 changes per second will
JMP BI generate 2 bits for each change resulting in 6000 bits per second
B2: RET (bps). In other words 3000 baud results in 6000 bps.