0% found this document useful (0 votes)
11 views

Chapter 3 Serial Interfacing With Microprocessor Based System

For ioe student, instrumentation

Uploaded by

Rakesh Chaudhary
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views

Chapter 3 Serial Interfacing With Microprocessor Based System

For ioe student, instrumentation

Uploaded by

Rakesh Chaudhary
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 87

INSTRUMENTATION II

BEL III/I
Presented By
Er. Suwarna Lingden
NEC Regd. No. 8632 'A'
B.E (E&C) , MScInE

TRIBHUVAN UNIVERSITY
INSTITUTE OF ENGINEERING
PURWANCHAL CAMPUS
DHARAN-8
SERIAL INTERFACING WITH MICROPROCESSOR BASED SYSTEM

• Within a microcomputer data is transferred in parallel, because that is the


fastest way to do it.
• For transferring data over long distances, however, parallel data transmission
requires too many wires and becomes expensive.
• Therefore, data to be sent long distances is usually converted from parallel to
serial so that it can be sent on a single wire or pair of wires.
• Serial data received from a distant source is converted to parallel form so that
it can easily be transferred on the microcomputer buses.
SERIAL INTERFACING WITH MICROPROCESSOR BASED SYSTEM

• In serial transmission from MPU to a peripheral , an 8-bit parallel word is


converted into a stream of eight serial bits; this is known as parallel to
serial conversion.
• After the conversion, one bit at a time is transmitted over a single line at a
given rate called the baud rate.
• In the serial reception, the MPU receives a stream of eight bits and they are
converted into an 8-bit parallel word; this is known as serial to parallel
conversion.
Serial Data Transmission
• The data are sent one bit at a time over the transmission channel.
• However, since most processors process data in parallel, the transmitter
needs to transform incoming parallel data into serial data and the receiver
needs to do the opposite.
• Serial data transmission is slow as compared to parallel transmission.
• Serial data can be sent synchronously or asynchronously.
Advantages of serial data transfer over parallel

• Longer data transmission in serial mode as less number of wires is used and
is cheaper to implement.

• Voltage loss is not much a problem in serial communication.


Serial : 1 = -3 V to -25 V 0 = +3 V to +25 V
Parallel : 1 = +5 V 0=0V

• Crosstalk is less of an issue because there are fewer conductors compared to


that of parallel cables.
Advantages of serial data transfer over parallel

• Many IC and peripherals have serial interface.


• Serial cable can be longer than parallel.
But in serial mode of transfer, only one bit of a word is transferred at a time so
that data transfer rate is very slow; it is one of the demerits over parallel data
transfer.
SYNCHRONOUS AND ASYNCHRONOUS TRANSMISSION

• In synchronous format, a receiver and a transmitter are synchronized.


• Data is transmitted or received based on a clock signal.
• Sync characters or flags are used to indicate the start of each synchronous data
stream or frame of data.
• This format is generally used for high-speed transmission (more than 20 Kbps)
SYNCHRONOUS AND ASYNCHRONOUS TRANSMISSION

• In asynchronous format , the receiving device does not need to be synchronized


with the transmitting device.
• Each character carries the information of the start and the stop bits.
• When no data are being transmitted, a receiver stays high at logic 1, called
Mark; logic 0 is called Space.
SYNCHRONOUS AND ASYNCHRONOUS TRANSMISSION

• Transmission begins with one Start bit (low), followed by a character and
one or two Stop bits (high). This is known as framing.
• This format is generally used for low-speed transmission (less than 20Kbps)
D0 D1 D2 D3 D4 D5 D6 D7

PS : In a little endian system, the least significant byte (the byte with the lowest memory address) is stored
first, followed by the more significant bytes. In a big endian system, the scheme is reversed.
RATE OF TRANSMISSION

• In serial I/O, one bit is sent out at a time; therefore, how long the bit stays on
or off is determined by the speed at which the bits are transmitted.
• Furthermore, the receiver should be set up to receive the bits at the same rate
as the transmission; otherwise, the receiver may not be able to differentiate
between two consecutive 0s and 1s.
Bit Rate and Baud Rate
• Bit rate is the number of bits per second.
• Baud rate is the number of signal changes or signal units per second.
Bit rate ≥ Baud rate
Q) If an analog signal carries 4 bits in each signal unit and if 1000 signal
units are sent per second, then find the baud rate and the bit rate.

Q) The bit rate of a signal is 3000. If each signal unit carries 6 bits, what is the
baud rate?
SERIAL DATA UNIT & SERIALIZATION

• SDU is a unit with 1 start bit, 7 or 8 data bits, 1 parity bit and 1 or 2 stop
bits.
• Start bit always has a value of 0 & stop bits always have a value of 1.
• For asynchronous data transmission, sender and receiver must be set up
to the same format
TRANSMITTING SDU

• The interface chip has a transmitter hold register for transmitting data which
first fetches the data bytes from CPU.
• According to the selected data format, the SDU logic puts the start bit in front
of data bits; it then calculates the parity bit and appends it together with the
stop bits to the data bits.
• Thus formed SDU is transferred into the transmitter shift register, which is
operated by a clock source determined by baud rate and thus provides the
individual bits at the serial output (LSB first). If no data, then the chip
possesses a logical high level
ERRORS IN SERIAL DATA TRANSFER

1. Parity error : The calculated parity does not coincide with the set parity.
i. Even parity,
ii. Odd parity,
iii. Mark parity,
iv. Space parity,
v. No parity
ERRORS IN SERIAL DATA TRANSFER

2. Framing error : Data does not fit into the frame that the data format and
baud rate defined i.e non-synchronized start/stop bit.

Eg. Change in no. of bits in receiving and transmitting end.


ERRORS IN SERIAL DATA TRANSFER

3. Break error

• If the reception line is at logic low level for longer time than the SDU
usually lasts, then the receiver assumes that the connection to the
transmitter has broken.

• Unless the transmitter drives the line to a logical high level, no data is
transferred.
ERRORS IN SERIAL DATA TRANSFER

4. Overrun error : If data arriving at the receiver is much faster than it can
be read by the receiver buffer; the latter received byte overwrites the
older data in the buffer.
ERROR CHECKING MECHANISMS

1. Parity check
• This is used to check each character by counting the number of 1s in the character.
• In the ASCII code transmission, bit D7 is used to transmit parity check information.

Parity system No. of 1s in the character D7


Even 0
Even
Odd 1
Odd 0
Odd
Even 1

Note : Even + 1 = Odd and Odd +1 = Even


For example :
• The ASCII (7 bits long) code for the character I is 49 H (100 1001) with
three 1s.
• When the character I is transmitted in an even parity system, the bit D7 is
set to 1, making the code C9 H (1100 1001) and even number of 1s is
transmitted.
• In an odd parity system, the character I is transmitted by keeping bit D7 = 0;
thus the code remains 49 H (0100 1001).
• Parity check cannot detect multiple errors in any given character.
2. Checksum

• This mechanism is used when blocks of data are transferred.

• It involves adding all the bytes in a block without carries.

• Then, the 2's complement of the sum (negative of the sum) is transmitted as
the last byte.

• The receiver adds all the bytes, including the 2's complement of the sum;
thus, the result should be zero if there is no error in the block.
2. Checksum

• If the result is not zero, an error is detected and the data is


retransmitted.

• For eg. Data blocks 41H, 42H and 43H are to be sent. Their sum is
C6H and 2's complement is 3AH. The receiver would then add all the
data blocks along with the 2's complement of the sum.

• If the result is zero then there is no error else an error is detected and
data is retransmitted.
3. Cyclic Redundancy Check
• A stream of data is represented by a polynomial that is divided by a constant
polynomial, and the remainder is generated.
• The remainder is sent out with data as a check for errors.
• The receiver checks the remainder to detect an error in the transmission.
SIMPLEX AND DUPLEX COMMUNICATION
STANDARDS IN SERIAL I/O
• The serial I/O technique is commonly used to interface terminals,
printers and modems with computers.
• Peripherals
and computers are designed and manufactured by various
manufacturers.
•A standard is normally defined which may include such items as
assignment of pin position for signals, voltage levels, speed of data
transfer, length of cables and mechanical specifications that can
ensure compatibility among different equipments.
STANDARDS IN SERIAL I/O
• In serial I/O, data can be transmitted as either current or voltage.
• When data are transmitted with voltage signal, the commonly used standards
are RS232C , RS423A and RS422A.
RS232

• RS-232 or Recommended Standard 232 is a standard originally introduced


in 1960 for serial communication transmission of data.
• RS-232 refers to the standard used to transfer serial communication and
not the actual connector.
• It formally defines signals connecting between a DTE (data terminal
equipment) such as a computer terminal, and a DCE (data circuit-
terminating equipment or data communication equipment), such as a modem.
RS-232
• The device should be either DCE or DTE.
• DCE devices should have a female DB-9 connector, and DTE devices
should have a male DB-9 connector.
• Any device that connects to a computer COM port using a straight through
serial cable is a DCE device.
RS232
• RS232 COM ports are normally configured as either a DTE (Data Terminal
Equipment) port or a DCE (Data Communications Equipment) port.
• Accordingto the standard, male connectors have DTE pin functions, and
female connectors have DCE pin functions.
• The COM port on a computer is a DTE port (male).
• The COM port on modems are configured as DCE port (female).
RS232

• Connect a DCE device to another DCE device using a null modem (male-to-
male) adaptor.
• Connect a DTE device to another DTE device using a null modem (female-
to-female) adaptor.
RS232

DB-9 or DE-9 DB-25 DB-9 or DE-9


(male connector) (male connector) (male & female connector)

RS232 Serial Port in I/O ports of PC Serial to USB converter


Fig : Connection of DTE and DCE through RS-232 interface
RS232

• For data lines, the voltage level +3 V and +15 V is defined as logic 0; from
-3 V to -15 V is defined as logic 1(normally,voltage levels are +/-12V). This
is negative true logic.
• Because of incompatibility of the data lines with the TTL logic, voltage
translators, called line drivers and line receivers, are required to interface
TTL logic with the RS-232 signals.
RS232

• The line driver, MC1488, converts logic 1 into approximately -9V and logic 0
into +9V.
• Before it is received by the DCE, it is again converted by the line receiver,
MC1489, into TTL-compatible logic.
RS232

5 5 5 5

Figure : RS-232C Connections (a) DTE to DCE (b) DTE to DTE


RS232

• The minimum interface between a computer and a peripheral requires three


lines : pins 2 (Tx), 3 (Rx), and 5 (Ground).
• These lines are defined in relation to the DTE ; the terminal transmits on pin 2
(Tx) and receives on pin 3 (Rx).
• The DCE transmits on pin 3 (Tx) and receives on pin 2 (Rx).
RS232

• The microcomputer, defined as a DTE, can be connected to the modem,


defined as a DCE, without any modification in the RS-232 cable.
• When a microcomputer, defined as a DTE, is connected to the printer, also
defined as a DTE, the transmit and receive lines must be crossed and this
connection is known as a null modem connection.
RS232 SIGNALS USED IN HANDSHAKING
RS232 RS232
RS232 SIGNALS USED IN HANDSHAKING

1. Data Terminal Ready (DTR'): After the terminal power is turned on


and terminal runs any self checks, it asserts data terminal ready (DTR’)
signal to tell the modem that it is ready.

2. Data Set Ready (DSR'): When the modem is powered up and ready to
transmit or receive data, it will assert data set ready (DSR’) to the terminal.
Under manual control or terminal control, modem then dials up the
computer. If the computer is available, it will send back a specified tone.
RS232 SIGNALS USED IN HANDSHAKING

3. Request to send (RTS'): When a terminal has a character ready to send,


it will assert a request-to-send (RTS’) signal to the modem.

4. Data Carrier Detect (DCD'): The modem will then assert its data-carrier-
detect (DCD’) signal to the terminal to indicate that it has established
connection with the computer.

5. Clear to send (CTS'): When the modem is fully ready to receive data, it
asserts the clear-to-send (CTS’) signal back to the terminal.
RS232 SIGNALS USED IN HANDSHAKING

6. Transmitted Data (TxD): The terminal then sends serial data characters
to the modem.

7. Received Data (RxD): Modem will receive data from terminal through
this line.

• Data Signal Rate Detect (DSRD): It is used for switching different baud
rate.
• Ring Indicator (RI) : Indicate that a ring has occured at modem; it works
independently.
NULL MODEM CONNECTION

• A null modem serves for data exchange between DTEs.


• Since both the computers are configured as DTEs, directly connecting them
by means of the conventional serial interface cable is impossible; not even
the plug fits into the jack of the second terminal.
• Also the TxD meets TxD and RxD meets RxD, DTR meets DTR and DSR
meets DSR etc.
NULL MODEM CONNECTION

• This means that outputs are connected to outputs and inputs are
connected to inputs.
• With this convention, no data transfer is possible.
• For the transmission of data, it is required to twist the TxD and RxD lines.
• In this way, the transmitted data of one terminal (PC) becomes received
data of other and vice versa.
Handshaking null modem connections
Handshaking null modem connections

Fig (a) : No hardware handshaking Fig (b) : Loopback handshaking

Fig (c) : Partial handshaking Fig (d) : Full handshaking


UNIVERSAL SERIAL BUS (USB)

• USB is an industry standard developed by a group of seven companies-


Compaq, DEC, IBM, Intel, Microsoft, NEC and Nortel in the mid -1990s that
defines the cables, connectors and protocols used for connection,
communication and power supply between computers and electronic devices.
• USB has effectively replaced a variety of earlier interfaces, such as serial and
parallel ports, as well as separate power chargers for portable devices.
• Packet based architecture with start frame, transactions, ACK and NAK
controls.
FEATURES OF USB

• Single connector type : USB replaces all the different legacy connectors
with one well-defined, standardized USB connector for all USB peripheral
devices, eliminating the need for different cables and connectors and thus
simplifying the design of the USB devices. So, all USB devices can be
connected directly to a standard USB port on a computer.

• Hot-swappable: USB devices can be safely plugged and unplugged as


needed while the computer is running. So, there is no need to reboot.
FEATURES OF USB

• Plug and Play: Operating system software automatically identifies,


configures, and loads the appropriate device driver when a user connects a
USB device.

• High performance: USB offers low speed (1.5 Mbit/s), full speed (12
Mbit/s) and high speed (up to 480 Mbit/s) transfer rates that can support a
variety of USB peripherals.USB 3.0(SuperSpeed USB) achieves the
throughput up to 5.0 Gbit/s. Latest USB 4 has transfer rate of 40 Gbits/s.
FEATURES OF USB

• Expandability: Up to 127 different peripheral devices may theoretically be


connected to a single bus at one time.

• Power supplied from the bus: USB distributes the power to all connected
devices eliminating the need for external power source for low-power
devices. High-power devices can still require their own local power supply.
USB also supports power saving suspend/resume modes.
FEATURES OF USB

• Easy to use for end user: A single standard connector type for all USB
devices simplifies the end user's task at figuring out which plugs go into
which sockets. The operating system automatically recognizes the USB
device attachment and loads appropriate device drivers.

• Low-cost implementation: Most of the complexity of the USB protocol is


handled by the host, which along with low-cost connection for peripherals
makes the design simple and low cost.
Wide range of workloads and applications:
• Suitable for device bandwidths ranging from a few kb/s to several Mb/s
• Supports isochronous as well as asynchronous transfer types over the same
set of wires
• Supports concurrent operation of many devices (multiple connections)
• Supports up to 127 physical devices
• Supports transfer of multiple data and message streams between the host and
devices
• Allows compound devices (i.e., peripherals composed of many functions)
• Lower protocol overhead, resulting in high bus utilization
• Isochronous bandwidth
- Guaranteed bandwidth and low latencies appropriate for telephony, audio, etc.
- Isochronous workload may use entire bus bandwidth.
• Robustness
- Error handling/fault recovery mechanism is built into the protocol
- Dynamic insertion and removal of devices is identified in user-perceived real-time
- Supports identification of faulty devices
SIGNALS , THROUGHPUT AND PROTOCOL

When D+ > D- : Differential '1'


When D- > D+ : Differential '0'
THROUGHPUT
• Throughput is the actual output of any device.
• USB’s actual throughput is a function of many variables:
➢ Target device’s ability to source or sink data
➢ Bandwidth consumption by other devices in the bus
➢ Efficiency of host’s USB ports
➢ Types of data
USB PROTOCOLS

• USB is made up of several layers of protocol.


• Each USB transaction consists of a
➢ Token Packet (Header defining what it expects to follow),
➢ Optional Data Packet (Containing the payload) and a
➢ Status Packet (Used to acknowledge transactions and to provide a
means of error correction)
• USB is a host centric bus so the host initiates all transactions.
USB PROTOCOLS

• The first packet, also called a token packet is generated by the host to
describe what is to follow and whether the data transaction will be a read or
write and what the device’s address and designated endpoint is.

• The next packet is generally a data packet carrying the payload and is
followed by an handshaking packet, reporting if the data or token was
received successfully, or if the endpoint is stalled or not available to accept
data.
USB Packet Fields
• Data on the USB bus is transmitted LSB first.
• USB packets consist of the following fields :

SYNC
• All packets must start with a sync field.
• The sync field is 8 bits long at low and full speed or 32 bits long for high
speed.
• It is used to synchronize the clock of the receiver with that of the transmitter.
• The last two bits indicate the end of the sync field and, by inference, where
the PID fields starts.
PID
• PID stands for Packet Identifier.
• This field is used to identify the type of packet that is being sent.
• There are 4 bits to the PID and to ensure it is received correctly, the 4 bits are
complemented(n represents complement) and repeated, making an 8 bit
PID in total.
• The resulting format is shown below:
DATA FLOW TYPES
• Control Transfers
Used for the configuration of the USB device.

• Bulk Data Transfers


Large sporadic (occurring at irregular intervals) transfers using all
remaining available bandwidth (but with no guarantee on bandwidth or
latency). A device like a printer, which receives data in one big packet, uses
the bulk transfer mode. A block of data is sent to the printer (in 64-byte
chunks) and verified to make sure it is correct.
• Interrupt Data Transfers
Devices that need guaranteed quick responses (bounded latency) where the
latency matters. A device like a mouse or a keyboard, which will be sending
very little data, would choose the interrupt mode.

• Isochronous Data Transfers


At some guaranteed speed (often but not necessarily as fast as possible)
but with possible data loss. A streaming device (such as speakers) uses the
isochronous mode. Data streams between the device and the host in real-
time, and there is no error correction.
DEVICES (NODES), HOSTS AND ON-THE-GO
USB HUBS
• Hub has two major roles: power management and signal distribution.
• Hubs can be linked, potentially giving you unlimited USB ports to your
computer.
• The biggest difference between types of hubs that is important to know when
dealing with USB devices is between un-powered and powered hubs
Powered Hub
• Needed when connecting multiple unpowered devices such as mice or digital
cameras.
• These low-powered devices derive their power source from the bus.
• If too many are connected through a hub, the computer may not be able to
handle it.
Un-powered Hub
• Un-powered hubs can be used with any number of high-power devices such
as printers and scanners that have their own power supply, thus not requiring
power from the bus.
• Safe to use with low-power devices (mice, cameras, joysticks, etc.) as long as
too many aren’t connected as once.
ON THE GO (OTG) PROTOCOL

• OTG specification defines a new type of USB device with both host and
peripheral capabilities called a "dual role device".
• Possess dual role – host or peripheral capability to switch between the two.
• Cell phones can exchange contact lists, phones can attach to printers and print
faxes.
• OTG devices must have Host Negotiation Protocol (HNP) and Session
Request Protocol(SRP).

You might also like