0% found this document useful (0 votes)
65 views65 pages

Instructions

This document discusses serial and parallel data communication. It describes simplex, half duplex, and full duplex communication links. It provides examples of using UART for serial data transmission in 8051 microcontrollers. It discusses synchronous and asynchronous serial data transmission, as well as standards like USART and UART. It provides code examples and explains how to initialize and use the SCON and TCON registers to transmit and receive serial data in 8051 in different modes like mode 0, 1, 2 and 3. It also discusses baud rates, common serial interfaces, and serial data interrupts.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
65 views65 pages

Instructions

This document discusses serial and parallel data communication. It describes simplex, half duplex, and full duplex communication links. It provides examples of using UART for serial data transmission in 8051 microcontrollers. It discusses synchronous and asynchronous serial data transmission, as well as standards like USART and UART. It provides code examples and explains how to initialize and use the SCON and TCON registers to transmit and receive serial data in 8051 in different modes like mode 0, 1, 2 and 3. It also discusses baud rates, common serial interfaces, and serial data interrupts.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 65

MC&ES

SERIAL DATA COMMUNICATION

7TH CLASS 22RD AUGUST 2023


SERIAL AND PARALLEL DATA COMMUNICATION
1 BIT AT A TIME/8 BIT AT A TIME
SIMPLEX-HALF DUPLEX-FULL DUPLEX-

• Simplex communication link: In simplex transmission, the line is dedicated for


transmission. The transmitter sends and the receiver receives the data.one way
• Half duplex communication link: In half duplex, the communication link can be used
for either transmission or reception. Data is transmitted in only one direction at a time.
• Full duplex communication link: data is transmitted in both ways at the same time, it
is a full duplex i.e. transmission and reception can proceed simultaneously
• This communication link requires two wires for data, one for transmission and one for
reception.8051 supports full duplex.
• /* * 8051_Serial_UART
• #include <reg51.h> /* Include x51 header file */
• void UART_Init() { TMOD = 0x20; /* Timer 1, 8-bit auto reload mode */ TH1 = 0xFD; /* Load
value for 9600 baud rate */ SCON = 0x50; /* Mode 1, reception enable */ TR1 = 1; /* Start
timer 1 */ } void Transmit_data(char tx_data) { SBUF = tx_data; /* Load char in SBUF register
*/ while (TI==0); /* Wait until stop bit transmit */ TI = 0; /* Clear TI flag */ } void String(char
*str) { int i; for(i=0;str[i]!=0;i++) /* Send each char of string till the NULL */
{ Transmit_data(str[i]); /* Call transmit data function */ } } void main() { UART_Init(); /*
UART initialize function */ String("test"); /* Transmit 'test' */ while(1); }
SERIAL DATA COMMUNICATION-SIMPLEX

• .Anexample is the interface between a keyboard and a


computer. Keyboard is the transmitter and the computer is the
receiver.
• Even in 2023 in the desktop serial data communication is used
for printers, keyboard, etc.
SYNCHRONOUS SERIAL DATA COMMUNICATION

• Synchronous serial data communication: In this transmitter and


receiver are synchronized. It uses a common clock to synchronize the
receiver and the transmitter. First the synch character is sent and then
the data is transmitted. This format is generally used for high speed
transmission. In Synchronous serial data communication a block of
data is transmitted at a time.
ASYNCHRONOUS

• Asynchronous Serial data transmission: In this, different clock


sources are used for transmitter and receiver. In this mode, data is
transmitted with start and stop bits. A transmission begins with start
bit, followed by data and then stop bit. For error checking purpose
parity bit is included just prior to stop bit. It transfers a single byte at
a time. 8051 supports Asynchronous
UNIVERSAL SYNCHRONOUS AND
ASYNCHRONOUS-USART

• USART stands for Universal Synchronous/Asynchronous Receiver-


Transmitter. USART uses external clock so it needs separate line to
carry the clock signal. Sending peripheral generates a clock and the
receiving peripheral recover from the data stream without knowing
the baud rate ahead of time
UART

• It stands for Universal Asynchronous Receiver-Transmitter. A UART


generates its internal data clock to the microcontroller. It synchronizes
that clock with the data stream by using the start bit transition. The
receiver needs the baud rate to know ahead of time to properly receive
the data stream. 8051 microcontroller has a built-in serial port called
UART.
BAUD RATE-SPEED

The rate at which the data is transmitted is called baud or transfer rate.
The baud rate is the reciprocal of the time to send one bit.
In asynchronous transmission, baud rate is not equal to number of bits per second.
This is because; each byte is preceded by a start bit and followed by parity and stop
bit.
For example, in synchronous transmission, if data is transmitted with 9600 baud, it
means that 9600 bits are transmitted in one second. For 10 bits 8 bits data transmitted

•  
SERIAL DATA COMMUNICATION-PROTOCOLS

• Over the years, dozens of serial protocols have been crafted to meet
particular needs of embedded systems.
• USB (universal serial bus), and Ethernet, are a couple of the well-
known computing serial interfaces.
• Other very common serial interfaces include SPI, I2C, RS-232 and
so on.
8051-SERIAL DATA –BUSINESS PARTERNS

• REGISTERS:-To Receive or To Transmit Data serially


• SBUF REGISTER(PHYSICALLY TWO REGISTERS)-DATA REGISTERS
• SCON & TCON REGISTERS-CONTROL REGISTERS
• PINS: PIN RXD(P3.0) &PIN TXD (P3.1) (10th and 11th Pins)
• FLAGS:TI &RI FLAGS ( IN BUILT IN SCON REGISTER)
• MODES:4 PROGRAMMABLE MODES
• TMOD &TCON REGISTERS-INDIRECTLY- FOR BAUD RATE GENERATOR
SERIAL DATA INTERRUPTS

• It is a relatively slow process.


• You can’t wait all the time to know data transfer is completed or not.
• Serial Data Flags are included in SCON register.
• Transmission is under the control of Programmer but not receiving.
• The flags TI & RI are ORed together to produce interrupt.
• U must clear the flags. In Timers automatic clearance.
SCON AND TCON

• Two Control Registers of involved with Serial Data Communication.


• Serial Port Control (SCON)
• Power Mode Control (PCON)
• PCON not that much important
SCON REGISTER
SM0: Serial port mode Bit 0 of serial port mode.
SM1: Serial port mode Bit 1 of serial port mode.
SM2: Enable multiprocessor
Enable multiprocessor communication in modes 2 and 3 (for 9 bit UART).
REN: Receiver Enable Bit
1 Enables 0 disables set/reset
TB8: Transmit bit 8 –useful in 9 bit data transmission-mode2 &3.
•RB8 – Receiver bit 8 useful in 9 bit data transmission-mode2 &3.
•or the 9th bit received in modes 2 and 3. Cleared by hardware if 9th bit
received is a logic 0. Set by hardware if 9th bit received is a logic 1.

•TI – Transmit Interrupt flag is automatically set at the moment the last


bit of one byte is sent. It’s a signal to the processor that the line is
available for a new byte to transmit. It must be cleared from within the
software.

•RI – Receive Interrupt flag is automatically set upon one byte to receive.


It signals that byte is received and should be read quickly prior to being
replaced by new data. This bit is also cleared from within the software.
• RB8: Receive bit 8.
• Ninth bit received (in modes 2 and 3):
• Mode 0 :Not used.
• Mode 1 : Stop bit.
• Mode 2, 3 : Ninth data bit.
PCON – POWER CONTROL REGISTER
PCON

• SMOD-This is the only bit useful for serial data communication


• Serial data modify bit. Set to 1 by program to double baud rate using timer 1
for modes 1,2 and3.
• Cleared to 0 by program to use timer 1 baud rate.
• GF1& GFO general purpose user defined flags
• PO & IDL not applicable in 8051
DATA TRANSMISSION &RECEPTION

Transmission – Data transmition is initiated by writing data to the SBUF register. TI


Flag is set to 1 when the data has been transmitted and signified that the SBUF is empty.
you must wait for the signal of TI flag.
Reception – Data receive through the RXD pin bit 
REN bit in SCON must be set or 1 position to receive data
For mode 0 RI must be cleared
RI flag is set to 1 after receiving all the data
Not under program control only through REN we have to control.
RECEPTION

• Reception can begin in modes1,2 and 3 if RI is set when serial stream


of bit begins
• RI must have been reset by program before the last bit is received or
incoming data will be lost.
• Incoming data is not transferred to SBUF until the last data bit has been
received so that the previous transmission can be read from SBUF
while new data is being received.
DATA TRANSMISSION MODES

• Works in four different modes Mode 0 ,1, 2 3


• Modes are selected by SM0 and SM1 bits in SCON
• Mode 0-fixed Baud Rate-Shift Register
• Other Modes Variable (1,2,3)-Timer 1 helps in this aspect
MODE 0-ONLY SYNCHRONOUS MODE

• In mode 0, serial data are transmitted and received through the RXD
pin, while the TXD pin output clocks. The baud rate is fixed at 1/12 the
oscillator frequency. On transmit, the least significant bit (LSB bit) is
sent/received first.
MODE 1

• UART is designed mainly for this mode and frame format of this mode is
compatible with COM port of PCs. The programmer can set its
transmission/reception rate using Timer 1.
• In mode 1, 10 bits are transmitted through the TXD pin or received through
the RXD pin in the following manner: a START bit (always 0), 8 data bits
(LSB first) and a STOP bit (always 1). The START bit is only used to initiate
data receive, while the STOP bit is automatically written to the RB8 bit of the
SCON register.
SERIAL DATA MODE ONE-

• SET SMO AND SM1 BITS to 01


• SBUF BECOME 10 BIT FULL DUPLEX RECEIVER &
TRANSMITTER
• 8 DATA BITS -ONE START BIT- ONE STOP BIT
• RXD PIN RECEIVES THE DATA
• TXD PIN TRANSMITS THE DATA
• ORDER OF TRANSMISSION:START BIT-LSB-MSB-STOP BITS
TRANSMISSION

• Data transmission begins by writing data to the SBUF register. The START and STOP bits
are added by hardware to form a 10-bit frame. Then, the 10-bit parallel-to-serial conversion
is performed and one bit (LSB first) at a time is transmitted through the TXD pin
• Once the complete frame is transmitted, the TI flag is set automatically by the serial port
hardware to indicate the end of data transmission
• We need to monitor the TI flag to conform that SBUF register is not overloaded
• If the TI flag is set, it implies that last character transmission is completed and now SBUF
is empty and
• then new byte can be written to it to start the next transmission. If a new byte is written to
SBUF before TI is raised, the
• Un transmitted part of the previous byte will be lost.
• It should be noted that the microcontroller sets the TI flag when it completes byte
transfer, whereas it must be cleared by the programmer after the next byte is loaded into
SBUF.
RECEPTION
• The data reception begins when REN = 1 and high-to-low transition (start bit) is detected on the RXD pin.
The received
• byte is loaded into SBUF register (the START and STOP bits are separated by UART hardware once
complete frame is received) and stop bit into RB8 (SCON bit 2) only if the following two conditions are met.
• (i) RI = 0, showing that previous data byte is read by the program
• (ii) Either SM2 = 0 or stop bit = 1. Normally SM2 = 0 and character will be accepted irrespective of the status
of stop bit. A program may check RB8 to ensure that the stop bit is correct, if required.

• If these two conditions are not met, the received character is ignored and RI is not set and the
receiver circuit waits for the next start bit
• EACH BIT TIME REMAINS LOW OR HIGH DURING CERTAIN TIME
INTERVAL
• TIME INTERVAL = 1/BAUD RATE FREQUENCY
• BIT WILL BE MAINTAINED HIGH OR LOW DURING THIS PERIOD
• RECEIVING INITIATED BY FALLING EDGE OF START BIT
• CONTINUES TILL HALFWAY OF NEXT START BIT
• ANTI NOISE MEASURE
WHEN 10 BITS ARE RECEIVED

• Start bit is discarded


• 8 data bits enters into SBUF register
• Stop bit is saved in RB8 bit of SCON
• RI becomes HIGH indicates new byte is received
• Check empty of SBUF before transmitting or receiving otherwise mix up with
previous data and leads to error.
MODE ONE BAUD RATES

• TIMER ONE IS USED TO GENERATE BAUD RATE / BAUD


FREQUENCY FOR MODE 1 USING OVERFLOW FLAG.
• TIMER 1 IN MODE 2 AUTORELOAD MODE
• MORE OVER FLOWS MORE BAUD RATE
PRE CONDITIONS TO RECEIVE DATA

• RI MUST BE ZERO
• BIT SM2 IS ZERO
• OR STOP BIT SHOULD BE ONE(GENERAL STATE)
• RI ZERO INDICATED PREVIOUS BYTE RECEIVED AND READY FOR NEXT
BYTE
• SM2 ZERO- STOP BIT CAN BE ANY STATE ZERO OR ONE-NOT MUCH USE
HERE
• SM2 =I RECEPTION OF ONLY GOOD STOP BITS-ANTI NOISE SAFE GAURD
BAUD RATE FREQUENCY

When Timer is in mode 2


• Fbaud= [2smod/32] x [Oscillator Clock Frequency] / [12d x
(256 d– (TH1)]
• If Timer is not in mode 2 then
• F BAUD = [2smod/32] x Timer 1 overflow Rate
For the 8051 the Timer 1' is used to generate the baud rate in Auto reload
mode.
STANDARD BAUD RATES

• As per protocols serial data communication is following


standard baud rates
• Example:9600 is standard baud rate
• Then the required oscillator frequency is 11.0592 MHz
EXAMPLE TO CALCULATE BAUD RATE

XTAL=11.0592 MHz is divided by 12 = 921.6 kHz and then, 921.6 kHz/32 = 28,800 Hz
is the frequency provided by UART to Timer 1 to set baud rates.
28,800/3= 9600 where, = FD is loaded with TH1
• 28,800/6= 2400 where, =F4 is loaded with TH1
• But, if you try to change the value loaded to TH1 other than listed above, The baud
rate will not be supported by the BIOS of the PC and serial communication between
8051 microcontroller may not occur properly. However, you can program PC to
transfer data at such speed.
Step 1: The baud rate in the 8051 is programmable and can be set through Timer
1.

Step 2: The 8051 has external clock of frequency 11.0592 MHz, which is first
divided by 12. After which the machine cycle frequency is 921.6 kHz.

Step 3: Now, machine cycle frequency 921.6 kHz is divided by the 8051
microcontroller serial communication UART circuitry by 921.6 kHz divided by 32
gives you the frequency of 28,800 Hz.

Step 4: The baud rate should be programmed in mode 2 as we use Timer 1. To get
baud rates compatible with PC, we must load TH1 with values: -3, -6, -12, -24.
These values are fixed to find out suitable baud rate compatible with PCs COM
port. PC baud rates values are set by the vendors and are fixed.
TXD(P3.1) RXD

8051 COM port of PC or device

RXD(P3.0) TXD
Division factor to achieve different baud rates
Baud Rate TH1 (Hex)
9600 FD
4800 FA
2400 F4
1200 E8
• Example 10-1

• With XTAL = 11.0592 MHz, find the TH1 value needed to have the following baud
rates. (a) 9600 (b) 2400 (c) 1200

• Solution:

• With XTAL = 11.0592 MHz, we have:

• The machine cycle frequency of the 8051 = 11.0592 MHz / 12 = 921.6 kHz, and 921.6 kHz / 32 = 28,800 Hz is the
frequency provided by UART to Timer 1 to set baud rate
WHAT VALUE SHOULD BE LOADED INTO THE TH1 REGISTER TO
GET A BAUD RATE OF (I) 9600 BITS PER SECOND, AND (II) 1200 BPS
FOR SERIAL TRANSMISSION? ASSUME CRYSTAL FREQUENCY TO
BE 11.0592 MHZ
•.
• The value of TH1 can be found as,
• TH1 = 256 – {(FOSC x 2SMOD) ÷ (12 × 32× FBAUD)}
• (i) For 9600 bps rate, assuming SMOD = 0
• TH1 = 256 – {(11.0592 × 106 × 1) ÷ (384 × 9600)} = 253 = FDH
• (ii) For 1200 bps rate, assuming SMOD = 0
• TH1 = 256 – {(11.0592 × 106 × 1) ÷ (384 × 1200)} = 232 = E8H
8051 MICROCONTROLLER PROGRAMMING STEPS

• Configure Timer 1 in auto-reload mode.


• Load TH1 with value as per required baud rate e.g. for 9600 baud rate load 0xFD. (-3 in
decimal)
• Load SCON with serial mode and control bits. e.g. for mode 1 and enable reception, load
0x50.
• Start timer1 by setting TR1 bit to 1.
• Load transmitting data in the SBUF register.
• Wait until loaded data is completely transmitted by polling the TI flag.
• When the TI flag is set, clear it, and repeat from step 5 to transmit more data.
Write a program to transfer the message “YES” serially at
9600 baud, 8-bit data, 1 stop bit. Do this continuously.

Write a program to transfer the message “YES” serially at 9600 baud,


8-bit data, 1 stop bit. Do this continuously.
PROGRAM THE 8051 TO RECEIVE BYTES OF DATA SERIALLY, AND PUT
THEM IN PI. SET THE BAUD RATE AT 4800, 8-BIT DATA, AND 1 STOP BIT

• .
SERIAL COMMUNICATION 8051 MICROCONTROLLER USING KEIL
• Simulation Result (In Keil μVision 4.0 IDE)
• The transmitted data using UART can be observed in serial output windows. Open serial
windows from “ View → Serial Windows → UART#1 menu. The snapshot of the output
is shown
MODE 2-• ASYNCHRONOUS MODE

• 11 bit data frame (start bit, 8 data bit, programmable 9 bit and stop bit)
• • On transmission 9th bit is TB 8 bit of SCON
• • On reception 9th bit is placed in RB 8 bit of SCON
• • 9th bit may be used for data or as a parity bit
• • Baud rate may be 1/32 or 1/64 of oscillator frequency
MODE 3

• is the same as Mode 2 in all respects except the baud


rate. The baud rate in Mode 3 is variable.

You might also like