Introduction RS232 I2C SPI
Introduction RS232 I2C SPI
& IOT
Prof. R. Sivacoumar
TT601, MEMS Design Lab
9952840844
What are sensor networks?
• Networks of devices that are able to sense the environment,
perform on-board computation, (and communicate)
• Why? Because we can: Technology
– Circuit integration.
• Ability to integrate more functions into chip with lower energy
– Wireless communication.
• Better communication theory
• Better devices
• Bit-rates are slowly increasing
• Transmission power is decreasing
– Sensor technology
Result: sensing nodes
PC-104+
UCLA TAG
UCB Mote
Embedded Networked Sensing
• Micro-sensors,
– on-board processing,
– wireless interfaces
– small scale and low cost => many
– monitor phenomena “up close”.
• Enables spatially and temporally dense monitoring.
– Nyquist Sampling – you must sample often enough (in time or space)
– Inverse problems are very difficult, e.g., by sensing the temperature at a
few places, determine the temperature everywhere (numerically
unstable). Instead, directly sense the temperature everywhere.
– Wireless interface allow little infrastructure – easy deployment
– Wireless interface allow cooperation and distributed computing
Sensor networks applications…
Embed numerous
sensing nodes to
monitor and interact
with physical world
17
Protocol Layers
• Reference model
– formally defines what is meant by a layer, a service etc.
• Service architecture
– describes the services provided by each layer and the
service access point
• Protocol architecture
– set of protocols that implement the service architecture
– compliant service architectures may still use non-
compliant protocol architectures
20
The seven Layers
Application Application
Presentation Presentation
Session Session
Transport Transport
Parallel
N bits transmitted at a time
over N data lines
1 word
Synchronization among all N
bits
25
Serial communication
• Single data wire, possibly also control and power wires
• Words transmitted one bit at a time
• Higher data throughput with long distances
– Less average capacitance, so more bits per unit of time
• Cheaper, less bulky
• More complex interfacing logic and communication protocol
– Sender needs to decompose word into bits
– Receiver needs to recompose bits into word
– Control signals often sent on same wire as data increasing protocol
complexity
26
Serial Communications
• Synchronous • Asynchronous
– Synchronous Peripheral Interface (SPI) – Serial Communication Interface (SCI)
• Constant transmission of data • Transmission of data through “words”
• Clocks of Transmitter and Receiver must • Continuous transmission unnecessary
be synchronized • Built-in safeguards against noise and
• No safeguard against error or noise error
• Data rates depend on clock rates • Transmitter and Receiver operate
• Flexible to communication with peripheral independently
devices • Requires start and stop bit for each
– LCD drivers, A/D converter, other byte of data
microprocessors – Sends constant ‘1’ for idle
• Simultaneously transmits and receives – Sends a ‘0’ for start and “1” for stop bits
data • Very reliable data reception
– Transmission line, Receiving line, and
Ground
Asynchronous Serial
• Transmission
With asynchronous communication, the transmitter and
receiver do not share a common clock
Add: Start, Stop, Parity Bits Remove: Start, Stop, Parity Bits
Transmitter + – Receiver
Data
¨ Shifts the parallel data onto ¨ Extracts the data using its own
the serial line using its own clock
clock
¨ Converts the serial data back to
¨ Also adds the start, stop and the parallel form after stripping
parity check bits off the start, stop and parity bits
Asynchronous Serial
Transmission
• Start bit—indicates the beginning of the data word
• Stop bit—indicates the end of the data word
• Parity bit—added for error detection (optional)
• Data bits—the actual data to be transmitted
• Baud rate—the bit rate of the serial port
• Throughput—actual data transmitted per sec (total bits transmitted—
overhead)
– Example: 115200 baud = 115200 bits/sec
– If using 8-bit data, 1 start, 1 stop, and no parity bits, the effective
throughput is: 115200 * 8 / 10 = 92160 bits/sec
Bit Types
• Idle 1
• Start bit 0
• Data bit 0 or 1
• Parity 0 or 1
• Stop bit 1
Data Data Data Parity
Idle
Bit 1 Bit 3 Bit 6 Bit
HIGH
Stop Bit
LOW
Start Data Data Data Data Data
Bit Bit 0 Bit 2 Bit 4 Bit 5 Bit 7
Ta Kim
Bit Types (Cont)
• Stop Bits –
• Bit at the end of a data word.
• Bit set to high “1”.
• Indicates the end of a word.
• Data bits –
• Data bits to be transmitted.
• Sender and receiver have to agree in the number of data bits.
(Usually 8 or 9)
• Least significant bit is sent first.
• Can be low or high.
Bit Types (Cont)
• Parity bit –
• Works as an error check.
• There are two types: odd and even
– Even: if number of 1’s in the data word is even.
– Odd: if number of 1’s in the data word is odd.
• Bit after the data bits and before the stop bit.
• Can prevent single noise signal, but does not recognize
when two bits are altered by noise.
• Used to prevent noise.
Bus types
1111 0 1 0 0 0 0 1 1 0 0 1111
1111 0 1 0 0 0 0 1 1 0 0 1111
?
bit period
V 0.3 74
Serial Peripheral Interface
• What is it?
• Basic SPI
• Capabilities
Serial Peripheral Interface
http://upload.wikimedia.org/wikipedia/commons/thumb/e/ed/
SPI_single_slave.svg/350px-SPI_single_slave.svg.png
• Protocol
• Uses
75
What is SPI?
• Serial bus protocol
• Fast, easy to use, and simple
• Very widely used
• Not “standardized”
76
SPI Basics
• A 4-wire communications bus
• Typically communicate across short distances
• Supports
– Single master
– Multiple slaves
• Synchronized
– Communications are “clocked”
77
SPI Capabilities
• Always full-duplex
– Communicates in both directions simultaneously
– Transmitted (or received) data may not be
meaningful
• Multiple Mbps transmission speeds
– 0-50 MHz clock speeds not uncommon
• Transfer data in 4 to 16 bit characters
• Supports multiple slaves
78
SPI bus wiring
• Bus wires
– Master-Out, Slave-In (MOSI)
– Master-In, Slave-Out (MISO)
– System Clock (SCLK)
– Slave Select/Chip Select (SS1#, …, SS#n or CS1, …, CSn)
• Master asserts slave/chip select line
• Master generates clock signal
• Shift registers shift data in and out
79
SPI signal functions
80
SPI uses a “shift register” model of
communications
Master shifts out data to Slave, and shifts in data from Slave
http://upload.wikimedia.org/wikipedia/commons/thumb/b/bb/SPI_8-bit_circular_transfer.svg/400px-SPI_8-bit_circular_transfer.svg.png
81
Two bus configuration models
slaves
http://upload.wikimedia.org/wikipedia/commons/thumb/f/fc/SPI_three_sla
ves.svg/350px-SPI_three_slaves.svg.png
82
SPI clocking: there is no “standard way”
• Four clocking “modes”
– Two phases
– Two polarities
• At CPOL=0 the base value of the clock is zero, i.e. the idle state is 0
and active state is 1.
– For CPHA=0, data are captured on the clock's rising edge (low→high
transition) and data is output on a falling edge (high→low clock
transition).
– For CPHA=1, data are captured on the clock's falling edge and data is
output on a rising edge.
• At CPOL=1 the base value of the clock is one (inversion of CPOL=0),
i.e. the idle state is 1 and active state is 0.
– For CPHA=0, data are captured on clock's falling edge and data is output
on a rising edge.
– For CPHA=1, data are captured on clock's rising edge and data is output on
a falling edge.
83
SPI timing diagram
Master and selected slave must be in the same mode
During transfers with slaves A and B, Master must
Configure clock to Slave A’s clock mode
Select Slave A
Do transfer
Deselect Slave A
Configure clock to Slave B’s clock mode
Select Slave B
Do transfer
Deselect Slave B
Master reconfigures clock
mode on-the-fly!
• Cons
– Slave select/chip select makes multiple slaves more
complex
– No acknowledgement (can’t tell if clocking in garbage)
– No inherent arbitration
– No flow control (must know slave speed)
85
The I C Bus
2
86 of 40
What is I C 2
87 of 40
What is I C used for?
2
88 of 40
I C Bus Characteristics
2
89 of 40
I C Bus Characteristics (cont’d)
2
• Master:
– Initiates a transfer by generating
start and stop conditions
– Generates the clock
– Transmits the slave address
– Determines data transfer direction
• Slave:
– Responds only when addressed
– Timing is controlled by the clock line
91 of 40
I C Bus Configuration Example
2
92 of 40
I C Hardware Details
2
93 of 40
I2C Electrical Aspects
SDA
SCL
Data line stable; Change
Data valid of data
allowed
95 of 40
Start and Stop Conditions
A transition of the data line while the clock line is high is
defined as either a start or a stop condition.
Both start and stop conditions are generated by the bus
master
The bus is considered busy after a start condition, until a stop
condition occurs
SDA SDA
SCL SCL
Start Stop
Condition Condition
96 of 40
I C Addressing
2
• Masters can be
– Transmitter only
– Transmitter and receiver
• Slaves can be
– Receiver only
– Receiver and transmitter
99 of 40
Acknowledgements
• Master/slave receivers pull data line low for one clock pulse
after reception of a byte
• Master receiver leaves data line high after receipt of the last
byte requested
• Slave receiver leaves data line high on the byte following the
last byte it can accept
Acknowledgement
from receiver
100 of 40
Acknowledgements
• From Slave to Master Transmitter:
– After address received correctly
– After data byte received correctly
• From Slave to Master Receiver:
– Never (Master Receiver generates ACK)
• From Master Transmitter to Slave:
– Never (Slave generates ACK)
• From Master Receiver to Slave:
– After data byte received correctly
101 of 40
Negative Acknowledge
• Receiver leaves data line high for one clock
pulse after reception of a byte
Transmitter releases SDA
line during 9th clock
pulse.
Not acknowledgement
(NACK) from receiver
102 of 40
Negative Acknowledge (Cont’d.)
• From Slave to Master Transmitter:
– After address not received correctly
– After data byte not received correctly
– Slave Is not connected to the bus
• From Slave to Master Receiver:
– Never (Master Receiver generates ACK)
• From Master Transmitter to Slave:
– Never (Slave generates ACK)
• From Master Receiver to Slave:
– After last data byte received correctly
103 of 40
Data Transfer on the I2C Bus
• Start Condition
• Slave address + R/W
– Slave acknowledges with ACK
• All data bytes
– Each followed by ACK
• Stop Condition
SDA
SCL
Remember : Clock is produced by Master
Start Stop
104 of 40
Data Formats
Master writing to a Slave
A A A
105 of 40
Data Formats Cont’d.
Master reading from a Slave :
Master is Receiver of data and Slave is Transmitter of data.
106 of 40
Data Formats Cont’d.
Combined Format
108 of 40
Arbitration Between Two Masters
• As the data line is like a wired AND, a ZERO address bit overwrites a ONE
• The node detecting that it has been overwritten stops transmitting and
waits for the Stop Condition before it retries to arbitrate the bus
109 of 40
Error Checking
• I2C defines the basic protocol and timing
– Protocol errors are typically flagged by the interface
– Timing errors may be flagged, or in some cases could be
interpreted as a different bus event
• Glitches (if not filtered out) could potentially cause:
– Apparent extra clocks
– Incorrect data
– “Locked” bus
• Microprocessors communicating with each other
can add a checksum or equivalent
110 of 40
Bus Recovery
• An I2C bus can be “locked” when:
– A Master and a Slave get out of synch
– A Stop is omitted or missed (possibly due to noise)
– Any device on the bus holds one of the lines low
improperly, for any reason
– A shorted bus line
• If SCL can be driven, the Master may send extra
clocks until SDA goes high, then send a Stop.
• If SCL is stuck low, only the device driving it can
correct the problem.
111 of 40
Type of I C Implementations
2
112 of 40
Available I C Devices
2
113 of 40
Available I C Devices
2
114 of 40
End use
• Telecom: Mobile phones, Base stations,
Switching, Routers
• Data processing: Laptop, Desktop, Workstation,
Server
• Instrumentation: Portable instrumentation,
Metering systems
• Automotive: Dashboard, Infotainment
• Consumer: Audio/video systems, Consumer
electronics (DVD, TV etc.)
115 of 40
Applications
• There are some specific applications for
certain types of I2C devices such as TV or radio
tuners, but in most cases a general purpose I2C
device can be used in many different
applications because of its simple
construction.
116 of 40
I2C designer benefits
• Functional blocks on the block diagram
correspond with the actual ICs; designs proceed
rapidly from block diagram to final schematic
• No need to design bus interfaces because the
I2C-bus interface is already integrated on-chip
• Integrated addressing and data-transfer protocol
allow systems to be completely software-defined
• The same IC types can often be used in many
different applications
117 of 40
I2C designer benefits
• Design-time improves as designers quickly become familiar with
the frequently used functional blocks represented by I 2C-bus
compatible ICs
• ICs can be added to or removed from a system without affecting
any other circuits on the bus
• Fault diagnosis and debugging are simple; malfunctions can be
immediately traced
• Software development time can be reduced by assembling a
library of reusable software modules
• The simple 2-wire serial I2C-bus minimizes interconnections so ICs
have fewer pins and there are fewer PCB tracks; resulting in
smaller and less expensive PCBs
118 of 40
I C Manufacturers benefits
2
119 of 40