AV-314
Assignment No.5
Name:
N/S Toseeq Haider
Pak No:
222609
Section:
99(B)
Submitted to:
Gp Capt Dr Mujahid Mohsin
Q No 1: Explain the basic principles of RS-232 communication, including signal levels,
baud rate, and handshaking signals? Describe the EUSART module in microcontrollers.
How does it differ from a standard UART?
Ans:
Fundamental Concepts of RS-232 Communications:
RS-232 (Recommended Standard 232) is an electrical standard for serial transmission of data.
RS-232 prescribes the signal's electrical characteristics and timing, signal meaning, and physical
size and pin arrangement of connectors. These are the essential concepts:
1.Signal Levels:
RS-232 sends binary data with voltage levels. RS-232 defines:
Logic "1" (mark) as -3V to -15V voltage.
Logic "0" (space) as a voltage between +3V and +15V.
They are not like the usual 0V and 5V (or 3.3V) for digital logic circuits, so level shifters will
usually be necessary to connect RS-232 with microcontrollers or other digital units.
2.Baud Rate:
Baud rate is defined as the signal changes per second. In RS-232, it is often equal to the number
of bits transmitted per second (bps).
Typical baud rates are 9600, 19200, 38400, 57600, and 115200 bps.
Transmitter and receiver need to be set to the same baud rate to communicate successfully.
3.Handshaking Signals:
Handshaking helps in managing data flow between devices to avoid data loss.
Typical handshaking signals in RS-232 are:
RTS (Request to Send): The transmitting device indicates that it is ready to transmit data.
CTS (Clear to Send): The receiving unit indicates that it is clear to send data.
DTR (Data Terminal Ready): Serves as an indication that the device is on and ready.
DSR (Data Set Ready): Serves as an indication that the receiving unit is ready.
DCD (Data Carrier Detect): Serves as an indication that the receiving unit has detected a
carrier signal.
RI (Ring Indicator): Serves to indicate an incoming call on a modem.
EUSART Module in Microcontrollers:
EUSART is the abbreviation for Enhanced Universal Synchronous Asynchronous Receiver
Transmitter. It is a peripheral in most microcontrollers that supports serial communication. This
is how it operates and how it is different from a regular UART:
1.Functionality:
UART (Universal Asynchronous Receiver Transmitter): A UART is a hardware module that
manages asynchronous serial communication. It translates parallel data from the microcontroller
into a serial flow for transmission and vice versa for reception.
EUSART: An EUSART adds synchronous communication functionality to a normal UART.
This allows it to work both in asynchronous and synchronous modes.
2.Modes of Operation:
Asynchronous Mode: Like the normal UART, it sends and receives data with no common clock
signal. It uses start and stop bits to enclose the data.
Synchronous Mode: In synchronous mode, the EUSART employs a common clock signal to
synchronize data receive and transmit operations, which can enhance data transfer speed and
reliability.
3.Features:
Baud Rate Generator: EUSART modules frequently incorporate a programmable baud rate
generator, enabling easy configuration of communication rates.
Framing Error Detection: Detects framing errors in the start, stop, or parity bits.
Parity Generation and Checking: Includes optional parity bits for error detection.
Multi-Processor Communication: Certain EUSART modules provide addressing modes for
multi-processor system communication.
4.Differences from Standard UART:
Synchronous Communication: The most significant difference is the capability to work in
synchronous mode, which a standard UART cannot.
Enhanced Features: EUSART modules tend to have extra features such as hardware flow control,
more advanced error detection, and support for multiple communication protocols.
Q No 2: Write a C program for a microcontroller PIC16F877A to:
(a)
Receive data from RS-232.
(b)
Convert and transmit it through EUSART.
(c)
Use a baud rate of 9600.
Provide proper comments in the code and describe how it works?
Explanation of the Code
Oscillator Frequency:
The statement #define _XTAL_FREQ 4000000 sets the oscillator frequency as 4 MHz, which
is utilized for baud rate calculation.
EUSART Initialization:
The function EUSART_Initialize() initializes the EUSART module for asynchronous communication
at 9600 baud rate.
The baud rate is calculated through the formula:
SPBRG=(Fosc/(64×Baud Rate))-1
For an oscillator of 4 MHz and 9600 baud rate, SPBRG is configured as 25.
The TX and RX pins (RC6 and RC7) are set as output and input, respectively.
Data Transmission:
The EUSART_Transmit() routine transmits a character via the EUSART. It waits until the transmit
buffer is free (TXSTA.TRMT) and then loads the data into the TXREG register.
Data Reception:
The EUSART_Receive() routine waits until data has been received (PIR1.RCIF) and reads the
data out of the RCREG register.
Main Loop:
The program is always receiving data from RS-232, optionally converting it (e.g., to uppercase),
and sending it back through the EUSART module.