Lec4 - Serial Commu Pro
Lec4 - Serial Commu Pro
Protocols
– Parallel: Faster / More expensive
Communication Protocols
– Serial: Cheaper / slower
Communication Protocols
• Parallel
• Parallel Vs. Serial
Vs. Serial
– Parallel: Faster / More expensive
• Parallel
• Faster
– Serial:
• More Cheaper
expensive / slower
• Serial
• Cheaper
• Slower
Serial Communication
• Transmission of one bit of information at a time.
• One bit -> a time delay -> next bit
• Peripheral devices such as printers, keyboards, scanners, and mice
operate have their own computer
• Communication problem can be generalized to one of transmitting
information between two computers.
• Serial channel is the collection of signals (or wires) that implement
the communication between 2 computers/devices/modules
• To improve bandwidth, remove noise and increase range,
• Place interface logic between the digital device and the serial channel.
define the data terminal equipment (DTE) as the computer or a term
Serial Channel
communication equipment (DCE) as the modem or printer.
Figure• Data
7.1.terminal
A serial channel
equipment connects
(DTE): the computer two
or a terminal thatdata
generateterminal
or receive eq
data
devices.
• Data communication equipment (DCE): equipment that facilitates the transmission
of data between DTE.
When transmitting in a serial fashion, there are many ways to encode b
Transmitting Data Serially
• Many ways to encode binary information on the line
• maximize bandwidth and minimize errors
• Non-return-to-zero (NRZ) encoding is a binary code in which signal is
never at zero voltage. Ex: UART
• Level the matches the logical signal (digital data (0/1) is converted to digital
signal(v/0)) where a 1 is a positive voltage or current
• More energy in the wire compared to typical VOL/VOH digital logic
• Always a voltage causing current to flow continuously
• On a twisted pair, voltages are differential.
• Binary values of 1 and 0 are encoded as positive or negative voltage
differences.
• In positive logic, 1 is a positive voltage difference and 0 is a negative voltage
difference.
• In negative logic, the voltage representing 0 is higher than the voltage representing
1.
a Example: NRZ Unipolar/bipolar
e
s
n
-
d
f
l
t
e
f
y
• Unipolar:
The clock highlightseither abovetransition
the different or belowmethods.
the axis NRZ is level sensitive
n related•toBipolar: Both
the values sides
being sent.of
RZaxis
has a transition for a 1 value with respect to
Transmitting Data Serially
• Non-return-to-zero-inverted (NRZI) – Ex USB
• Method of encoding binary signal as transitions or changes in the signal.
• Transitions in the middle of the clock cycle, but this only occurs when there
is a 0/1 depending the type of NZRI
• Similar to NRZ, the signal in a NRZI protocol is never zero.
• Binary information is encoded as the presence or absence of a transition at
a clock boundary,
• Both the transmitter and receiver will synchronize their clocks so the
receiver knows when to look for the transition.
• Transition is a change from positive to negative or from negative to positive
• Send a 1 by placing a transition on the signal, or send a 0 by causing no
transition
• NRZI might take the opposite convention, as in Universal Serial Bus (USB),
where a transition means 0 and a steady level means 1.
Example: NRZI
1 start bit, 1 stop bit, 8 data bits, no parity, baud rate = 9600
Serial Communication - UART
Serial
• Universal Asynchronous Receiver Communication
and Transmitter (UART)
• UART is asynchronous full-duplex communication
• Universal Asynchronous Receiver and Transmitter (UART)
• Asynchronous – UART is programmable.
• Sender provides no •clock signal to receivers
Asynchronous
• Full-duplex – Sender provides no clock signal to receivers
• Separate Tx and Rx line – FT232R converts the UART port to a standard USB interface
implementing serial communication
• USART – Supports synchronous
UART
communication
• Universal Asynchronous Receiver/Transmitter
(UART)
• Asynchronous communication,
• Full duplex.
• Only two data lines (along with third line for
common ground) are sufficient for minimum
connectivity.
• The communicating UART devices can be either a
microcontroller or any other device equipped
with UART interface.
• Each data byte is transmitted sequentially bit by
bit, as single standalone UART frame.
• On the receiver side, the received bits are
assembled to reconstruct the data byte.
Flow Control
• If during data transmission, the receiving device runs out of buffer space and
it becomes essential to inform the transmitter to stop further data
transmission. This additional control signaling between transmitter and
receiver is called flow control.
• Flow control can be implemented using hardware or software.
• Hardware flow control: dedicated hardware connections are used for flow control
purpose.
• Software flow control: no extra hardware is required. Rather a communication protocol
implemented as part of the software is used for flow control purpose.
• UART has also been used extensively for modem connections. In that context, it is
possible to employ hardware flow control. For that purpose, dedicated lines labeled as
request to send (RTS) and clear to send (CTS) are used in addition to UART receive
(U_RX) and transmit (U_TX) data lines.
UART Frame Format
• When data of appropriate size (5 to 8 bits) is passed to the UART
module for transmission, a Start bit is placed at beginning of the
data. The Start bit is the first bit that is transmitted by the
transmitter and is marked by the transmission of logic low level for
one bit duration.
• If the UART module is idle before the beginning of transmission, its
transmit pin (labeled as U_TX) is kept at logic level high.
• The start of UART frame transmission is marked by a logic “Low” to
low transition on U_TX pin generated by the transmitter and is
sensed by the receiver.
• Stop bit is High
UART Data Transmission
• At the completion of Start bit transmission, the first data bit (corresponding to LSB of data)
is transmitted followed by bit by bit transmission of the entire data field.
• After the transmission of last data bit, the optional parity bit, if configured, is transmitted.
• Finally, one or two stop bits are transmitted to mark the end of UART frame transmission.
The transmission of next UART frame can start immediately after the transmission of stop
bit(s) corresponding to previous UART frame.
Example
A typical UART frame comprising of 1 Start bit, 8 data bits,
• A typical UART frame comprising of 1 Start bit, 8 data bits, 1 parity bit and 1
1 parity bit and 1 stop bit is shown below where S is the Start
stop bit is shown below where S is the Start bit, D0-D7 are the data bits. D0 is
bit,parity
the LSB, P is the D0-D7bitareand
theEdata bits.stop
is the D0 bit.
is the LSB, P is the parity bit
and E is the stop bit.
• 3-communication systems
• Master-slave configuration
• Ring Network
• Multi-drop System
• UART is mostly 1-master, 1-
slave communication
Synchronous Transmission
Stop
Stops Start Stop Start
A = 0x41 B = 0x45
Clock
Data
A = 0x41 B = 0x42
Synchronous Transmission – I2C
• The Inter-integrated Circuit (I2C)
• I2C Protocol is a protocol intended to allow multiple “slave” (or secondary)
digital integrated circuits (“chips”) to communicate with one or more “master”
chips.
• Multi-master system, allowing more than one “master ” (or primary) to
communicate with all devices on the bus
• When multiple primary devices are used, the master devices can’t talk to each other
over the bus and must take turns using the bus lines.
• In I2C there are three additional modes specified:
• Fast-mode plus, at 1MHz;
• High-speed mode, at 3.4MHz; and
• Ultra-fast mode, at 5MHz.
I2C Characteristics
• Serial, byte-oriented
The SCL clock is used in a synchronous fashion to communicate on the bus. Even though
• Multi-master, multi-slave
data transfer is always initiated by a master device, both the master and the slaves have
• Two bidirectional lines,
control plus
over ground
the data rate. The master starts a transmission by driving the clock low, but i
a slave wishes to slow down the transfer, it too can drive the clock low (called clock
• Serial Data Linestretching).
(SDA) In this way, devices on the bus will wait for all devices to finish. Both addres
• Serial Clock Line (SCL)
(from Master to Slaves) and information (bidirectional) are communicated in serial
• SDA and SCL need to pull
fashion up with resistors
on SDA.
I2C Communication Signals
• 5-componenets for communications:
• START: master to initiate a transfer
• DATA: sent in 8-bit blocks (MSB first) and consists of
• 7-bit address and 1-bit direction from the master
• control code for master to slaves
• information from master to slave
• information from slave to master
• ACK: used by slave to respond to the master after each 8-bit data transfer
• RESTART: used by the master to initiate additional transfers without
releasing the bus
• STOP: used by the master to signal the transfer is complete and the bus is
free
I2C Bus Connection
• Each device connected with the I2C bus can be either in master mode or in
slave mode.
• But only a master device can initiate the data transfer process.
• Usually, there are one master and one slave or multiple slave devices connects
with the same I2C bus through pull-up resistors.
• Each salve address has a 7-bit unique address.
then subsequent data transmissions contain information sent from master to
Timing Diagram
For a write data transfer, the master drives the RDA data line for 8 bits, then
drives the acknowledge condition during the 9 clock pulse. If the direction
th
• Timing diagram:
iming diagram:
Figure 7.15. A synchronous serial interface between a microcon
an I/O device.
system clock SCLK
Table 7.8 lists the SSI0 registers on the LM3S/TM4C. The LM3S/TM4C ca
slave mode, but we will focus on master mode. The PCTL bits are defined
writing data output:and 4.4.
MOSI or MISO Address 31-6 3 2 1 0 N
reading data input
$400F.E61C SSI3 SSI2 SSI1 SSI0 S
in the middle of bit:
3 ‐ 41
SSI Signaling
• The SSI bus can operate with a single master device and with one or
more slave devices
• If a single slave device is used, the SS pin may be fixed to logic low
• Most slave devices have tri-state outputs so their MISO signal
becomes high impedance (logically disconnected) when the device is
not selected
• Devices without tri-state outputs can't share SPI bus segments with other
devices
• Only one such slave could talk to the master, and only its chip select could
be activated
peripheral. It uses a single clock signal which is used to clock the
shift registers in each transmitter and receiver. The shift registers
SSI Operation
each have a small FIFO for buffering. The clock signal is shown as
being bidirectional: in practice it can be supplied by one of the
devices or by the device that is transmitting. Obviously care has to
be taken to prevent the clock from being generated by both sides
• Data registers in the master and the slave form a distributed register
and this mistake is either prevented by software protocol or
through the specification of the interface.
• When a data transfer operation is performed, this distributed register is
Serial peripheral interface
serially shifted by the SCK clock from the master
This bus is often referred to as the SPI and is frequently used
• SCK, is a 50% duty cycle clock generated on
byMotorola
the master.
processors such as the MC68HC05 and MC68HC11
microcontrollers to provide a simple serial interface. It uses the
• Can shift in burst mode basic interface as described in the previous section with a shift
register in the master and slave devices driven by a common clock.
• Transmitting device uses one edge of the clock to change its output, and the
It allows full-duplex synchronous communication between the
MCU and other slave devices such as peripherals and other
receiving device uses the other edge to accept the data
processors.
SPDR — m a st e r M C U SPDR — sl a v e M C U
M OSO
0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7
SS
SCK
M O SI
Data Transmission
• To begin a communication, the bus master first configures the clock,
using a frequency less than or equal to the maximum frequency the
slave device supports. Such frequencies are commonly in the range
of 10 kHz–100 MHz
• The master then transmits the logic 0 for the desired chip over the
chip select line. A logic 0 is transmitted because the chip select line
is active low, meaning its off state is a logic 1; on is asserted with a
logic 0
• If a waiting period is required (such as for analog-to-digital
conversion), then the master must wait for at least that period of
time before starting to issue clock cycles
stable. Data available is the time when the out
is the time when the input data must be valid.
Data Transmission During transmission, the output data will be v
S5min after the next clock edge. The maximum
• Transmission starts by software putting dataand intothethe transmit
minimum is 0.FIFO
Whenby writingthe set
receiving
to the SSI0_DR_R register hold time (S9) is 2 system bus periods. In orde
• Or, getting from the receive FIFO by reading from the the
error, SSI0_DR_R register.
data available from the device that is
• If data in FIFO Tx SSI distributed shift registerbefore will and end after) the data required by the
transmit that
this overlap that will determine the maximum
• SSI shift register transmits and receives bits at the same time can occur. The concepts of da
communication
• Distributed 8- to 32-bit register is serially shifted 4 topreviously
presented 16 bit positions
in Sectionby
4.2.the
SCK clock
• In implementation need to select which
edge of clk to transmit and other to
Receive
Data Transmission
• Data valid from S5max (clk edg) to S5min (clk edg)
• S5 time is 1 system bus period (20ns for 50MHz)
• Communication to occur without error, the data available from the device
that is driving the data line must overlap (start before and end after) the data
required by the other device that is receiving the data
• This overlap that will determine the maximum frequency at which
synchronous serial communication can occur
X 0 1 12 bits of data 0 Load input register; DAC regi
Example: Interface Maxim MAX5353 digital to analog unchanged.
converter with TM4C123...
X 1 0 XXXXXXXXXXXX X Update DAC register from inp
• Maxim MAX5353 12-bit digital to analog converter – This is the data
1 1 1 XXXXXXXXXXXX X Shutdown
• Word size: Initialization command first 3-bits (hence 000), then data 12-bits
(MSB first), then stop 1-zero
0 1= Total
1 information 16-bits
XXXXXXXXXXXX X No operation
• Clock phase: MAX5353 samples data on rising edge, so SSI must change data
Table 7.9. MAX5353 protocols
on falling edge. Polarity does not matter.
• BW: MAX5353 min clock low width = 40ns. Min Period = 80 ns. So, SSI period
>80ns. Say 100ns
Universal Serial Bus (USB)
• Based on Polling – initiated by host
• Asynchronous, Half duplex
• Host-controlled, token-based high-speed serial network
• Handle many devices with different speed
• Much more complex than other 3-protocols
• Maximum range within 4-meters
• Now USB on 4th generation (USB 1, 2, 3, and 4): Varies on data transfer rates,
appearance, and direction of data processing
• USB 1: 2 speed, 1.5, 12 Mbps
• USB 2: 3 speed, 1.5, 12, 480 Mbps
• USB 3: Max 5Gbps
• USB 4: Max 40 Gbps
hub or function, as shown in Figu
power to each device switching o
USB Hub other devices. The hub can filter o
• USB uses a tiered star topology, using a hub devices do not receive them. Beca
to connect additional devices. connected.
• A hub is at the center of each star.
• Each wire segment is a point-to- point
connection between the host and a hub or
function, or a hub connected to another
hub or function,
• Hub provides power, it can monitor power
to each device,
• switching off a device that is drawing too much
current without disrupting other devices.
• The hub can filter out high speed and full speed
transactions so lower speed devices do not
receive them
USB-2 Architecture
• Uses 7-bit address, up to 127 devices can be connected.
• Use 4-shielded wires (+5V power, D+, D- and ground)
• D+ and D- are twisted pair differential data signals.
• Uses Non-Return to Zero Invert (NRZI) encoding to send data with a sync field
to synchronize the host and receiver clock
USB Operation
• USB drivers will dynamically load and unload.
• When a device plugged into the bus, the host will detect this addition, interrogate the
device and load the appropriate driver.
• Similarly, when the device is unplugged, the host will detect its absence and automatically unload the
driver.
• USB architecture comprehends four basic types of data transfers:
• Control Transfers: Used to configure a device at attach time and can be used for other
device-specific purposes, including control of other pipes on the device.
• Bulk Data Transfers: Generated or consumed in relatively large quantities and have wide
dynamic latitude in transmission constraints.
• Interrupt Data Transfers: Used for timely but reliable delivery of data, for example,
characters or coordinates with human-perceptible echo or feedback response
characteristics.
• Isochronous Data Transfers: Occupy a pre-negotiated amount of USB bandwidth with a
pre-negotiated delivery latency. (Also called streaming audio/video real- time transfers).
Pull-up Resistors
• USB device indicates its speed by pulling either the D+ or D- line to 3.3 V,
with pull-up resistor
• pull-up resistor attached to D+ specifies full speed, and a pull-up resistor
attached to D- means low speed.
• Device-side resistors are also used by the host or hub to detect the presence
of a device connected to its port.
• Without a pull-up resistor, the host or hub assumes there is nothing connected.
is used to synchronize the clock of the receiver with th
USB Packets ID) is used to identify the type of packet that is being
The address field specifies which device the packet is
• USB transaction consists of three packets length allows for 127 devices to be supported. Addres
• Token Packet (header), is not yet assigned an address must respond to packets
• Host initiates all communication, field is made up of 4 bits, allowing 16 possible endpoi
• Describes the type of transaction, direction, device address and designated endpoint
can only have 2 additional endpoints on top of the def
• Optional Data Packet, (information) Checks are performed on the data within the packet p
• Contains information and Data bit CRC while data packets have a 16-bit CRC. EOP s
• Status Packet (acknowledge) Frame Packets (SOF) consist of an 11-bit frame numb
• Reporting if the data or token was received
500nssuccessfully,
on a fullorspeed
if the endpoint is stalled
bus or every or µs ± 0.0625 µs
125
not available to accept data
Packet Fields
• Sync: All packets start with Sync field.
• 8 bits long at low and full speed or 32 bits long for high speed and is used to synchronize the
clock of the receiver with that of the transmitter
• 00000001 that becomes with NRZI as D+(0)10101011 or, D-(1)01010100
• PID (Packet ID): Used to identify the type of packet that is being sent
• Address: Specifies which device the packet is designated for
• 7-bits. 127 devices to be supported
• Address 0 is not valid, as any device which is not yet assigned an address must respond to
packets sent to address zero
• Endpoint: is made up of 4 bits, allowing 16 possible endpoints
• Low speed devices, can only have 2 additional endpoints on top of the default pipe
• Cyclic Redundancy Checks (CRC5/CRC16): Performed on the data within the packet
payload.
• All token packets have a 5- bit CRC
• Data packets have a 16-bit CRC.
Example
• How a clk is synchronized with Sync: 00000001 bit?
• As USB uses NRZI format bit sequence 00000001 will become Z+=10101011, and Z-
=01010100. So, the receiver understand the clock.
• If, Address = 1100111, ENDP=0011, and polynomial (known by receiver and
sender) = x^5 + x^3 + x^2 + 1, what is CRC5.
• Representation of polynomial = 101101
• Do XOR on (1100111 0011 0000) by 101101 repetitively from left to right
Packet Fields
• End of packet (EOP): 2-bits
• Frame Number: 11-bit frame number is sent by the host every 1ms ± 500ns on a full speed
bus or every 125 μs ± 0.0625 μs on a high speed bus
• End points (ENDP): Part of Token. described as sources or sinks of data, shown as EP0In ,
EP0Out
• As the bus is host centric, endpoints occur at the end of the communications channel at the USB
function.
• Host software may send a packet to an
endpoint buffer in a peripheral device.
• If the device wishes to send data to the host,
the device cannot simply write to the bus as
the bus is controlled by the host.
• Therefore, it writes data to endpoint buffer
specified for input, and the data sits in the buffer
until such time when the host sends a IN packet to
that endpoint requesting the data.
• Endpoints can also be seen as the interface
between the hardware of the function device and the
firmware running on the function device.
Group PID Packet Identifier
Value
1001
OUT Token, Address + endpoint
1011 DATA1