You are on page 1of 10

Communicating

Using I2C and SPI

1 2 3 4 5
MEMBERS

Owen Largo Noel Novela

1 2 3 4 5
INTRODUCTION
The I2C (Inter-Integrated Circuit) and SPI (Serial Peripheral Interface) standards were created to
provide simple ways for digital information to be transferred between sensors and microcontrollers
such as Arduino. Arduino libraries for both I2C and SPI make it easy for you to use both of these
protocols.

The choice between I2C and SPI is usually determined by the devices you want to connect. Some
devices provide both standards, but usually a device or chip supports one or the other.

I2C has the advantage that it only needs two signal connections to Arduino-using multiple devices on
the two connections is fairly easy, and you get acknowledgment that signals have been correctly
received. The disadvantages are that the data rate is slower than SPI and data can only be traveling in
one direction at a time, lowering the data rate even more if two-way communication is needed. It is also
necessary to connect pull-up resistors to the connections to ensure reliable transmission of signals (see
the introduction to Chapter 5 for more on pull-ups).

1 2 3 4 5
INTRODUCTION
The advantages of SPI are that it runs at a higher data rate, and it has separate input and output
connections, so it can send and receive at the same time. It uses one additional line per device to select
the active device, so more connections are required if you have many devices to connect.

Most Arduino projects use SPI devices for high data rate applications such as Ethernet and memory
cards, with just a single device attached. I2C is more typically used with sensors that don't need to send
a lot of data.

This chapter shows how to use I2C and SPI to connect to common devices. It also shows how to
connect two or more Arduino boards together using I2C for multiboard applications.

1 2 3 4 5
I2C
The two connections for the I2C bus are called SCL and SDA. These are available on a standard Arduino board using analog pin 5 for SCL, which
provides a clock signal, and analog pin 4 for SDL, which is for transfer of data (on the Mega, use digital pin 20 for SDA and pin 21 for SCL). One
device on the I2C bus is considered the master device. Its job is to coordinate the transfer of information between the other devices (slaves) that are
attached. There must be only one master, and in most cases the Arduino is the master, controlling the other chips attached to it. In the example picture
below, it depicts an I2C master with multiple I2C slaves.

1
2 3 4 5
I2C
I2C devices need a common ground to communicate. The Arduino Gnd pin must
be connected to ground on each I2C device.

Slave devices are identified by their address number. Each slave must have a
unique address. Some I2C devices have a fixed address (an example is the
nunchuck while others allow you to configure their address by setting pins high
or low or by sending initialization commands.

Arduino uses 7-bit values to specify I2C addresses. Some device data sheets use
8-bit address values. If yours does, divide that value by 2 to get the correct 7-bit
value.

I2C and SPI only define how communication takes place between devices the
messages that need to be sent depend on each individual device and what it does.
You will need to consult the data sheet for your device to determine what
commands are required to get it to function, and what data is required, or
returned.

2
1 3 4 5
I2C
I2C and SPI only define how communication takes place
between devices the messages that need to be sent depend
on each individual device and what it does. You will need
to consult the data sheet for your device to determine what
commands are required to get it to function, and what data
is required, or returned.

The Arduino Wire library hides all the low-level


functionality for 12C and enables simple commands to be
used to initialize and communicate with devices.

3
1 2 4 5
SIP
Recent Arduino releases (from release 0019)
include a library that allows communication with
SPI devices. SPI has separate input (labeled
"MOSI") and output (labeled "MISO") lines and a
clock line. These three lines are connected to the
respective lines on one or more slaves. Slaves are
identified by signaling with the Slave Select (SS)
line. Example picture shows the SPI connections.

4
1 2 3 5
Arduino digital pins used for SI
SPI signal

SCLK (clock)
Standard Arduino board

13
P
Arduino Mega

52

MISO (data out) 12 50

MOSI (data in) 11 51

SS (slave select) 10 53

5
1 2 3 4
THANK YOU!

Owen Largo Noel Novela

1 2 3 4

You might also like