Serial Communication in 8051 𝝁𝝁C
Program ISR Program
a
SBUF TxD Pin
Interrupt
d
{P3.1}
Ti Ti = 1
Processor
u n
F
Ri MOV SBUF, A
g
CLR Ti
r
RxD Pin
i n Program ISR Program
e
SBUF
{P3.0}
e
8051 Microcontroller
in
Interrupt
g
For Serial Communication, 8051 has two pins: TxD {P3.1} for Ri = 1
n
serial transmission and RxD {P3.0} for serial reception.
E
SBUF register {8 bits} will give and take data serially for serial
communication on TxD and RxD. MOV A, SBUF
In serial communication, 1st it will send/receive LSB and at last CLR Ri
it will send/receive MSB. To configure serial communication, we need to configure SCON
Once, 1Byte transmission is completed, Ti interrupt tells register of 8051.
processor 8 bits transmission is completed.
Once, 1Byte Reception is completed, Ri interrupt tells processor
8 bits reception is completed.
Engineering Funda Android App 8051 YT Playlist
SCON Register in 8051 𝝁𝝁C
SCON Serial Control register – SM2 – Enables Multiprocessor System with Mode 2 and Mode 3.
{Bit Address SCON.7 to SCON.0} REN – Receiver Enable
a
REN = 0, receiver disabled
SM0 SM1 SM2 REN TB8 RB8 TI RI
d
REN = 1, receiver enabled
n
SM0 & SM1 – Mode Control bits TB8 – Transmitted bit 8 {Technically it is programmable 9th bit in
u
SM0 SM1 Serial Mode Description Baud Rate mode 2 and 3}
F
Mode 0 – not used
0 0 Mode 0 Shift Register Fosc/12
g
Mode 1 – stop bit ‘1’
in
0 1 Mode 1 8 bit UART Variable Mode 2 & 3 – Parity bit, programmed by programmer.
1 0 Mode 2 9 bit UART Fosc/32 or Fosc/64
er RB8 – Received bit 8 {Technically it is programmable 9th bit in
e
1 1 Mode 3 9 bit UART Variable mode 2 and 3}
n
Mode 0 – not used
i
Mode 0 {Shift Register sends only data} Mode 1 – stop bit ‘1’
D0 D1 D2 D3 D4
n
D5 D6
gD7 Mode 2 & 3 – Parity bit, programmed by programmer.
E
Mode 1 {8 Bit UART, 1st Start bit 0, then 8bits data and at last RI – Receive Interrupt
stop bit 1} It will be one after SBUF receives 8 bits data.
RI will be cleared by programmer in ISR program.
0 D0 D1 D2 D3 D4 D5 D6 D7 1
TI – Transmit Interrupt
Mode 2 & 3 {9 Bit UART, 1st
Start bit 0, then 8 bits data, 1 bit It will be one after SBUF transmits 8 bits data.
parity and at last stop bit 1} TI will be cleared by programmer in ISR program.
0 D0 D1 D2 D3 D4 D5 D6 D7 P 1
RS 232 Protocol
Basics of RS 232 Protocol Pin Details of DB9 and DB25 connector
RS 232 protocol is used for serial communication.
RS 232 protocol provides Asynchronous full duplex
a
communication. {Without Clock}
d
RS 232 protocol can handle serial communication with the
n
distance of 50ft, depending on cable type and bit rate.
u
RS 232 protocol can handle maximum data rate of 1Mbps.
F
As we increase the length of cable, capacitance will also increase Pin-D9 Pin-D25 Signal Source Type Description
g
which will limits the data rate.
in
Some special cables are also available, by which we can have 1 8 CD DCE Control Carrier Detect
r
communication up to 130fts. 2 3 RX DCE Data Receive Data
e
RS 232 protocol uses DB9 or DB25 connector for serial
e
communication. 3 2 TX DTE Data Transmit Data
DB9.
g i n
In DB25 connector, only Nine lines are used as it is there with 4 20 DTR DTE Control Data Terminal
Ready
n
Connectors of RS 232 Protocol 5 7 SG - - Signal Ground
E 6
7
6
4
DSR
RTS
DCE
DTE
Control
Control
Data Set Ready
Request to Send
8 5 CTS DCE Control Clear to Send
9 22 RI DCE Control Ring Indicator
- Rest None - - -
RS 232 Protocol
DTE and DCE of RS 232 Protocol Voltages of RS 232 Protocol
DTE – Data Terminal Equipment. {Computer}
DCE – Data Communication Equipment. {Modem} 15V Logic 0 15V
a
Communication happens between DTE and DCE, we can not have
d
communication between two DTE or two DCE. 5V
n
For two DTE communication, we use Null modem in between 3V
Tx Side
u 0 Voltage Rx Side
two DTE for communication.
F
In Null Modem, we just need to configure Rx, Tx and SG lines of
g
DB9 or DB25 connector. -3V
-5V
er in -15V Logic 1 -15V
RS232
i n e Handshaking of RS 232 Protocol
g
RTS of DTE is connected with CTS of DCE and visa versa.
n
DSR of DTE is connected with DTR of DCE and visa versa.
DCE
E
DTE Tx of DTE is connected with Rx of DCE and visa versa.
SG of DTE and DCE is commonly connected.
1st DTE is giving RTS {Request to Send} Signal to DCE.
If DCE is not busy then only DCE sends respond on DTR {Data
RS232 Null RS232 Transmit Ready}
Modem Then DTE can send data to DCE.
Similarly DCE can also initiate data transmission.
DTE DTE
RS 232 Protocol
Data Frame Format of RS 232 Protocol RS 232 Protocol in Embedded System
Data Frame Format of RS 232 Protocol is similar to UART. Majority of embedded system work with voltage range of 0 to 5V
and RS 232 works with ±15V.
a
Start Data {8 bits} Parity Stop To make data transfer compactible, we need to use MAX 232 IC
d
bit = 0 Bit Bit = 1 with embedded system to enable RS 232 Protocol.
n
MAX 232 converts voltage range of (0-5V) into ±25V and visa
u
In one frame of RS 232 Protocol, along with 8 bits of data, start
versa.
F
bit, stop bit and parity redundancy is also added.
Parity bit is optional but it can be used to identify the error in NOTE: MAX 232 will also limit the data transfer speed of RS 232
g
data reception. Protocol.
r i n
e e
g in
E n 0 to 5 Voltage ±30 Voltage
MAX 232 Board
Typical Embedded System DTE
Engineering Funda Android App 8051 YT Playlist