Professional Documents
Culture Documents
com/duncan1890
An Introduction to I C 2
and SPI
Protocols Frédéric Leens
T
oday, at the low end of the communication protocols The I2C bus was developed in 1982; its original purpose was
we find the inter-integrated circuit (I2C) and the serial to provide an easy way to connect a CPU to peripheral chips in
peripheral interface (SPI) protocols. Both protocols a television set. Peripheral devices in embedded systems are
are well suited for communications between integrated cir- often connected to the microcontroller as memory-mapped I/O
cuits for slow communication with on-board peripherals. The devices. One common way to do this is connecting the peripher-
two protocols coexist in modern digital electronics systems, als to the microcontroller parallel address and data busses. This
and they probably will continue to compete in the future, as results in lots of wiring on the printed circuit board (PCB) and
both I2C and SPI are actually quite complementary for this additional “glue logic” to decode the address bus on which all
kind of communication [1]. the peripherals are connected. In order to spare microcontroller
At the roots of these popular protocols, we find two major pins, additional logic, and to make the PCBs simpler (in other
companies—Motorola for SPI and Philips for I2C—and two words, to lower the costs), Philips labs in Eindhoven, The Neth-
different histories about why, when, and how the protocols erlands, invented the “inter-integrated circuit,” IIC or I2C proto-
were created. The SPI was introduced with the first microcon- col that only requires two wires for connecting all the peripher-
troller that derived from the same architecture as the popular als to a microcontroller. The original specification defined a bus
Motorola 68000 microprocessor announced in 1979. For those speed of 100 kb/s. The specification was reviewed several times,
who do not remember, the 16-bit 68000 microprocessor was at notably introducing the 400 kb/s speed in 1995 and, since 1998,
that time indisputably the best microprocessor on the market 3.4 Mb/s for even faster peripherals. As of October 1, 2006, no li-
and was used in the Apple Macintosh computer in 1984. The censing fees are required to implement the I2C protocol, making
microcontroller series was the 68xx. One of the first micro- official a type of “fair open policy” that Philips Semiconductor
controllers with an SPI bus was the M68HC03. The Motorola has always demonstrated with I2C [4]. Strictly speaking, fees are
M68HC11 microcontroller, still available today, is also derived still required to “officially” allocate slave I2C addresses.
from this architecture. SPI was defined as the external micro- NXP (formerly Philips Semiconductor) and Freescale
controller bus and was used to connect the microcontroller (formerly the semiconductor branch of Motorola) are today
peripherals with four wires. Unlike I 2C, it is hard to find a in charge for the I2C and SPI “official” specifications, although
formal separate “specification” of the SPI bus—for a detailed the protocols have become so popular that we could wonder if
“official” description, one has to read the microcontroller data they are not rather de facto public protocols. Let’s review each
sheets and associated application notes [2], [3]. of these protocols.
Clock Stretching
In an I2C communication, the
master device determines
Fig. 7. I2C 10-bit addressing. A 10-bit address is split into two words. The first word contains a conventional code on its the clock speed. The SCL sig-
five most significant bits to mark a 10-bit address, followed by the 2 MSBs of the 10-bit address and the Rd/nWR bit. The nal is an explicit clock signal
second address word contains the eight LSBs of the 10-bit address. This addition ensures backward compatibility with
on which the communica-
the 7-bit addressing scheme.
tion synchronizes.
2 However, there are situations where an I2C slave is not able
Table 1—I C addresses reserved for special
purposes. Xs are “don’t care” to cooperate with the clock speed given by the master and
Address Purpose needs to slow it down a little. This is done by a mechanism
General call–addresses all devices referred to as clock stretching and is made possible by the par-
0000000 0 ticular open-drain/pull-up structure of an I2C bus line.
supporting the general call mode
An I2C slave is allowed to hold down the clock if it needs
0000000 1 Start byte
to reduce the bus speed. The master, on the other hand, is
0000001 X CBUS addresses
required to read back the clock signal after releasing it to high
0000010 X Reserved for different bus formats
state and wait until the line has actually gone high.
0000011 X Reserved for future purpose
00001XX X High-speed master code
High Speed Mode
11110XX X 10-bit slave addressing
Fundamentally, the use of pull-ups to set a logic ONE limits the
11111XX X Reserved for future purposes maximum speed of the bus. This may be a limiting factor for
many applications. This is why the 3.4 Mb/s high speed mode
anything else goes wrong, this would mean that the device was introduced. Before using this mode, the bus master must is-
“talking on the bus” (master or slave) would know it by sue a specific “High Speed Master” code at a lower speed mode
simply comparing what it sends with what is seen on the bus. (e.g., 400 kb/s fast mode) (refer to Table 1), which initiates a ses-
If a difference is detected, a STOP condition must be issued, sion at 3.4 Mb/s. Specific I/O buffers must also be used to let the
which releases the bus. bus shorten the signals rise time and increase the bus speed. The
I2C also has some advanced features, like extended bus ad- protocol is also somewhat adapted in such a way that no arbitra-
dressing, clock stretching, and the very specific 3.4 Mb/s high tion is performed during the high speed transfer. Refer to the I2C
speed mode. specification for more information about the high speed mode.