5.serial Communication - 1
5.serial Communication - 1
01/04/24 1
1.serial communication
Fundamentals of serial communication
Serial communication means data transfer is bit by bit.
It has 3 modes of operation
a) simplex
transmitter receiver
2
transmitter receiver
receiver transmitter
receiver transmitter
3
*data transmission is in both ways. i.e. Simultaneously
serial communication to work the byte of data must be
converted to serial bits using a parallel –in –serial out shift
register ,then it can be transmitted over a single data line.
sync sync d d
transmitter receiver
6
start stop stop
data
mark
space
7
Rate of transmission
The rate at which the bits are transmitted in
bps.
Baud: The number of signal changes per one second.
As far as conductor wire is concerned, the baud rate and
bps are same and hence they are interchangeable
Error checks in data communication:
Parity check can only one bit of error can be detected.
Check sum is another variety to check error. Check
sum is a sum of all data byte string (without carry).
8
Data communication over telephone
Serial to Modem
Microcont parallel
roller converter
9
RS232C cable
1488 1489
2
DCE
1489 3
DTE 1488
Modem
7
10
Data Terminal Equipment : Generally computer or
microprocessor that are sending and receiving
data.
Data communication equipment modems and
other equipment that are used to send data for
long distance.
Digital data communication uses modem and &
standard phone lines.
Max 232:
It is a single chip ,which converts TTL levels
to Rs232c to voltage levels and vice versa.
11
VCC
C3
1 2
6
C1 3 C4
4
C2 GND
5
11 T1 in T1 out 14
12 R1 out R1 in 13
10 T2 in T2 out 7
9 R2 out R2 in 8
gnd
TTL side 15 RS232 side 12
8051
MAX232
P3.1 11 11
TxD 5
14 2 gnd
13 3
P3.0 10 12
RxD
DB--9
13
VCC
13 11
14 15
12 16
10
17
MAX233
2 T1 in T1 out 5
3 R1 out R1 in 4
1 T2 in T2 out 18
20 R2 out R2 in 19
gnd 14
TTL side RS233 side
SERIAL COMMUNICATION
NAME EXAMPLE A
With XTAL = 11.5092MHz, find the TH1 value needed to
have the following baud rates. (a) 9600 (b) 2400
(c)1200
Solution:
With XTAL=11.0592MHz, we have :
The machine cycle frequency of the
8051=11.0592/12=921.6KHz, and 921.6KHz/32=28,800Hz
is the frequency provided by UART to timer 1 to set baud
rate.
16
11.0592MHZ MACHINE
CYCLE 28800HZ
FREQ
17
TIMER 1 TH1 VALUES FOR VARIOUS BAUD RATES
4800 -6 FA
2400 -12 F4
1200 -24 E8
18
SBUF register
It is an eight bit register used for serial communication
in 8051.
19
•The following is a program to transfer letter ‘A’ serially at 4800
baud , continuously. Observe the status of serial window, serial
port and timer port for results.
NAME EXAMPLE 16
ORG OH
MOV TMOD,#20H; Timer 1, mode 2(auto reload)
MOV TH1,# -6 H; 4800 baud rate
MOV SCON,#50H; 8 BIT,1 Stop, REN enabled
SETB TR1; Start timer 1
AGAIN: MOV SBUF, #”A”; letter A to be transferred
HERE: JNB TI,HERE ; Wait for the last bit
CLR TI; clear T1 for next char
SJMP AGAIN ; keep sending A
END
20
• The significance of TI flag: once the timer is on
TI is reset(=0). When the stop bit is transferred, 8051
rises the TI flag is set, indicating that the last character
was transmitted and ready to transfer next character. By
monitoring TI flag we make sure that we are not
overloading the SBUF register. When 8051 finishes
transferring a byte, it raises the TI flag to indicate it is
ready for the next character. After SBUF is loaded
with a new byte, TI flag is forced to zero to
transmit the new byte.
.
21
The following is a program to transfer a message ‘YES’ serially
at 9600 baud, 8-bit data,1-stop bit , continuously. Observe the
results on serial window, serial port, and timer 1.
NAME EXAMPLE 17
ORG 0H
MOV TMOD,#20H; timer 1, mode2
MOV TH1,#-3H; 9600 baud rate
MOV SCON,#50H; 8-BIT, 1-stop bit, REN
enabled
SETB TR1; start timer 1
AGAIN: MOV A, #”Y” ; Transfer ‘y’
ACALL TRANS
MOV A,#”E”
ACALL TRANS
MOV A,#”S”; TRANSFER S
22
ACALL TRANS
SJMP AGAIN ; Keep doing it
: serial letter transfer subroutine
TRANS: MOV SBUF,A; Load SBUF
HERE: JNB TI,HERE ; wait for the last bit to transfer
CLR TI ; Get ready for next byte
RET
END
23
PROGRAMMING THE 8051 TO RECEIVE DATA SERIALLY
To transfer character bytes serially, the following steps must be
followed:
the TMOD register loaded with the value 20h, indicating the timer 1 in
mode 2 to the baud rate.
The TH1 is loaded to set the baud rate for serial data transfer.
The SCON register is loaded with the value 50h,indicaitng the mode 1 ,
where an 8-bit data is started with start and stop bits.
TR1 is set to start timer1.
RI is cleared by software.
The RI bit is monitored to whether entered character is received or not.
When RI is raised, SBUF has the byte, move its contents to a safe place.
To transfer next character, go to step 5.
24
The importance of RI flag : when the stop bit is received
during receiving, 8051 makes RI=1, indicating that an
entire byte is received.