2. Computers transfer data in two ways:
Parallel
8 or more lines (wire conductors) are used to
transfer data.
Serial
The data is sent one bit at a time
Sender Receiver Sender Receiver
Serial Communication
Parallel Communication
3. Parallel communication
All bits of data are sent at a time.
Data transfer speed is high.
It is not preferred for long distance communication as
it requires more number of wires and becomes
expensive.
Used for short distance communication
Serial communication
Only one bit is sent at a time.
Data transfer speed is low.
Used for long distance communication.
4. In serial communication,
At the transmitting end, the byte of data is
converted into serial bits(using a parallel-in-
serial-out shift register)
At the receiving end, the serial data is received
and packed into byte(using a serial-in-parallel-
out shift register)
5. There are three types of communication systems
Simplex – Data can be transmitted only in
one direction at a time.
Half Duplex – Data can be transmitted only
in one direction at a time.
Full duplex – Data can be transmitted in both
directions at a time.
7. In synchronous communication, common clock is
used for transmitter and receiver.
A separate link is used to transmit the clock signal.
In Asynchronous communication, the
synchronization is achieved only at the beginning of
the transmission.
To transfer data in serial communication, the
receiver and sender agree on set of rules called
protocol.
Synchronous and Asynchronous
serial communication
8. Serial data communication uses two methods:
Synchronous method - Block of data is transferred at
a time.
– Block-oriented data transfers use the synchronous
method
Asynchronous method –
– A single byte of data is transferred at a time.
– Is widely used for character-oriented transmissions
Instructions can be written to use either of these
methods.
9. Format of Asynchronous serial data frame
A non-divisible group of bits which can be
transmitted at a time is called frame.
A frame consists of the actual data and extra
bits(called overhead bits) to maintain
synchronization of the data.
A frame has one start bit, data bits, parity bits and
stop bits.
Each character is placed in between start and stop
bits, this is called framing
The start bit is always one bit
The stop bit can be one or two bits
The start bit is always a 0 (low)
11. Data Transfer Rate
In serial data communication data transfer rate is
defined in bps (bits per second)
Another widely used terminology is baud rate – the
number of signal changes per second
Baud rate and number of signals per second should
not be considered to be same.
Example: Let two signals be encoded in single
transition and consider that the signal is changing
after every 5ms.
Baud rate = (1/5ms) = 500
Number of bits per second = 2x200=400bits /s
12. RS 232 Standard
In serial communication for long distances, special
devices were developed to use telephone lines for
communication between two computers which are at
a long distance.
These devices are called Data Communication
Equipment(DCE). Ex- Modem
The devices that send or receive data are called Data
Transmission Equipment(DTE). Ex –Computers
For the maintenance of compatibility between DCE’s
manufactured by different manufacturers and to
establish communication signals between DTE and
DCE an interfacing standard RS232 wad developed.
RS stands for Recommended standard.
14. Since not all pins are used in PC cables, IBM
introduced the DB-9 version of the serial I/O
standard
Image source: Google
15. Data Communication equipment
Classification
Data communication equipment is classified as:
DTE (Data Terminal Equipment)-Terminal and
computers that send and receive data
DCE (Data Communication Equipment) -
Communication equipment, such as modems
The simplest connection between a PC and
microcontroller at least requires - three pins, TxD,
RxD, and ground
Image source: Google
16. RS232 Pins
DTR (data terminal ready)
When terminal is turned on, it sends out signal DTR to
indicate that it is ready for communication
DSR (data set ready)
When DCE is turned on and has gone through the self-test,
it asserts DSR to indicate that it is ready to communicate
RTS (request to send)
When the DTE device has byte to transmit, it asserts RTS
to signal the modem that it has a byte of data to transmit
17. CTS (clear to send) When the modem has room for
storing the data it is to receive, it sends out signal CTS
to DTE to indicate that it can receive the data now
DCD (data carrier detect)
The modem asserts signal DCD to inform the DTE
that a valid carrier has been detected and that
contact between it and the other modem is
established
RI (ring indicator)
An output from the modem and an input to a PC
indicates that the telephone is ringing
It goes on and off in synchronous with the ringing
sound
18. Handshaking (Co-ordination) process between
DTE and DCE
When the power is turned ON, DTE sends Data Terminal
Ready(DTR) signal to inform DEC that is ready .
When DCE is ready, it sends Data Set Ready(DSR) signal
to DTE.
After receiving DSR signal, DTE sends request to use data
channel by sending RTS signal to start transmission.
19. DCE at other end is dialed. The DCE at receiving end
replies by sending signal.
After receiving the signal, DCE sends Data Carrier
Detect(DCD) to DTE.
Then DCE sends Clear to Send(CTS) signal.
Now DTE on transmitter side starts sending signal.
20. RS232 Standards
An interfacing standard set by the Electronics
Industries Association (EIA) in 1960.
Since it was set long before the advent of the TTL
logic family, its input and output voltage levels are
not TTL compatible
In RS 232 a logic high is voltage between -3V to -25
V
and logic low is voltage between +3V to +25 V.
In TTL a logic high is +5V and logic low is 0V
Hence to connect TTL compatible microcontroller to
RS 232 system, a voltage converter is needed.
MAX232 and MAX 233 are most widely used voltage
converters.
22. MAX 232 has two set of line drivers for transferring and
receiving data.
Line drivers used for TxD( transmission)are called T1
and T2.
Line drivers used for RxD(receiving) are called R1 and
R2.
T1 line driver has designation T1in and T1out.
T1in pin is the TTL side and is connected to TxD of
microcontroller while T1out is RS232 side that is
connected to RxD pin of RS 232 DB connector.
R1 line driver has designation R1in and R1 out.
The R1in pin is RS232 side connected to TxD pin of
RS232 DB and R1 out is TTL side connected to RxD pin of
23. MAX233
To save board space, some designers use MAX233 chip
from Maxim
MAX233 performs the same job as MAX232
But eliminates the need for capacitors
MAX233 and MAX232 are not pin compatible
24. Serial Data Buffer(SBUF) Register
SBUF is an 8-bit register used for serial communication.
For a byte data to be transferred using serial mode, it
must be placed in the SBUF register.
When a byte is written into SBUF, it is framed with the
start and stop bits and transferred serially via the TxD
line
SBUF also holds the byte of data when it is received by
8051 RxD line.
When the bits are received serially via RxD, the 8051
deframes it by eliminating the stop and start bits, and
then placing the byte in SBUF
25. Serial Control(SCON) Register
This register is used to configure baud rate,
synchronization clock source.
It contains status bits which indicate whether the
data is transmitted completely and any new data is
received.
26. SCON Register
SM0, SM1-They determine the framing of
data by specifying the number of bits per
character, and the start and stop bits
SM2 - This enables the multiprocessing
capability of the 8051
SM0 SM1 Mode
0 0 Serial mode 0
0 1 Serial mode 1
1 0 Serial mode 2
1 1 Serial mode 3
27. Serial Port Modes
SM0 SM1 Mode Description Baud Rate
0 0 Serial mode 0 8-bit shift register 1/12 of the
clock
frequency
0 1 Serial mode 1 8-bit UART Determined by
timer 1
1 0 Serial mode 2 9-bit UART 1/12 of clock
frequency
1 1 Serial mode 3 9- bit UART Determined by
timer 1
28. SCON Register
REN (receive enable)
When it is high, it allows 8051 to receive data on
RxD pin
When it is low, the receiver is disabled.
TI (transmit interrupt)
When 8051 finishes the transfer of 8-bit character
it raises TI flag to indicate that it is ready to
transfer another byte
TI bit is raised at the beginning of the stop bit
29. RI (receive interrupt)
When 8051 receives data serially via RxD, it gets rid
of the start and stop bits and places the byte in SBUF
register
It raises the RI flag bit to indicate that a byte has
been received and should be picked up before it is lost
RI is raised halfway through the stop bit
TI and RI are set by hardware and must be cleared by the
software.
30. Programming Serial Data Transmitting
In programming the 8051 to transfer character bytes
serially
TMOD register is loaded with the value
20H(indicating the use of timer 1 in mode 2 (8-bit
auto-reload) to set baud rate)
TH1 is loaded with one of the values to set baud rate
for serial data transfer
SCON register is loaded with the value
50H(indicating serial mode 1, where an 8-bit data is
framed with start and stop bits)
31. TR1 is set to 1 to start timer 1
TI is cleared by CLR TI instruction
The character byte to be transferred serially is
written into SBUF register
The TI flag bit is monitored with the use of
instruction JNB TI, xx to see if the character has been
transferred completely.
32. Importance of TI Flag
The transmission of a character through TxD,
involves following steps
The byte character to be transmitted is written into
the SBUF register
The start bit is transferred
The 8-bit character is transferred on bit at a time
The stop bit is transferred
During the transfer of the stop bit that 8051 raises
the TI flag indicating that the last character was
transmitted
33. By monitoring the TI flag, we make sure that SBUF
is not overloaded.
If another byte is loaded into the SBUF before TI is
raised, the untransmitted portion of the previous
byte will be lost.
By checking the TI flag bit, we know whether or not
the 8051 is ready to transfer another byte
34. It must be noted that TI flag bit is raised by 8051
itself when it finishes data transfer
It must be cleared by the programmer with
instruction CLR TI
If we write a byte into SBUF before the TI flag
bit is raised, we risk the loss of a portion of the
byte being transferred.
35. Programming Serial Data Receiving
RI is cleared by CLR RI instruction
The RI flag bit is monitored with the use of
instruction JNB RI,xx to see if an entire character
has been received yet
When RI is raised, SBUF has the byte, and its
contents are moved into a safe place
36. Importance of RI Flag
In receiving the data through RxD pin the following
steps are involved
At first start bit is received indicating that the next
bit is the first bit of the character byte it is about to
receive
The 8-bit character is received one bit at a time
The stop bit is received
When receiving the stop bit 8051 makes
RI = 1,indicating that an entire character byte has
been received and must be picked up before it gets
overwritten by an incoming character
37. By checking the RI flag bit when it is raised we
can know that a character has been received
completely and is in SBUF register.
The SBUF contents are shifted to a safe place in
some other register or memory before it is lost
After the SBUF contents are copied, the RI flag bit
must be forced to 0 by CLR RI in order to allow
the next received character byte to be placed in
SBUF
Failure to do this causes loss of the received
character
38. Doubling Baud Rate
There are two ways to increase the baud rate of data
transfer
To use a higher crystal frequency.
To change a bit in the PCON register
PCON register is an 8-bit register
It is not a bit-addressable register
When 8051 is powered up, SMOD is zero
We can set it to high by software and thereby
double the baud rate