Hardware Reference
In-Depth Information
You've already learned about two important digital communication methods
available to you on the Arduino: the I 2 C bus and the serial UART bus. In this
chapter, you learn about the third digital communication method supported by
the Arduino hardware: The Serial Peripheral Interface bus (or SPI bus for short).
Unlike the I 2 C bus, the SPI bus uses separate lines for sending and receiving
data, and it employs an additional line for selecting which slave device you are
talking to. This adds additional wires, but also eliminates the issue of needing
different slave device addresses. SPI is generally easier to get running than I 2 C
and can run at a faster speed. In this chapter, you use the Arduino's built-in SPI
library and hardware to communicate with a digitally controllable potentiometer.
You use the potentiometer to control both LED brightness and speaker volume,
allowing you to make a simple audio/visual display.
NOTE Followthestepsofthischapterwiththistutorialvideo, www.jeremyblum
.com/2011/02/20/arduino-tutorial-8-spi-interfaces .Youcanalsofind
thisvideoontheWileywebsiteshownatthebeginningofthischapter.
OverviewoftheSPIBus
Originally created by Motorola, the SPI bus is a full-duplex serial communica-
tion standard that enables simultaneous bidirectional communication between a
master device and one or more slave devices. Because the SPI protocol does not
follow a formal standard, it is common to find SPI devices that operate slightly
different (the number of transmitted bits may differ, or the slave select line
might be omitted, among other things). This chapter focuses on implementing
the most commonly accepted SPI commands (which are the ones that are sup-
ported by the Arduino IDE).
WARNING BearinmindthatSPIimplementationscanvary,soreadingthe
datasheetisextremelyimportant.
SPI can act in four main ways, which depend on the requirements of your
device. SPI devices are often referred to as slave devices . SPI devices are synchro-
nous, meaning that data is transmitted in sync with a shared clock signal (SCLK).
Data can be shifted into the slave device on either the rising or falling edge of
the clock signal (called the clock phase ), and the SCLK default state can be set to
either high or low (called the clock polarity ). Because there are two options for each,
you can configure the SPI bus in a total of four ways. TableĀ 9-1 shows each of the
possibilities and the modes that they correspond to in the Arduino SPI library.
 
Search WWH ::




Custom Search