Hardware Reference
In-Depth Information
Table 10-1. ( continued )
Abbreviation
Definition
SPIE (SPI interrupt enable)
Turns on interrupt handling for SPI events
SPE (SPI enable)
Turns SPI core on or off
DORD (data order)
Sets the data order of a transfer to most-significant-bit-first or least-
significant-bit-first
MSTR (master/slave select)
Enables the master mode in the SPI core
CPOL (clock polarity)
Defines the clock polarity when idle
CPHA (clock phase)
Determines when data is set and when it is read in correlation to the
rise and fall of the clock
SPR1, SPR0, SPI2X (SPI clock rate select)
Used together to determine the clock divider and speed of the SPI
network
SPSR (SPI status register)
Stores flags regarding the SPI transfer; also holds the SPI2X value
SPIF (SPI interrupt flag)
Is set when an event triggers the SPI interrupt and is cleared on read
WCOL (write collision)
Is written when data is written to the SPDR during a transfer
SPDR (SPI data register)
Holds the incoming and outgoing data of an SPI transfer
Connecting Two Devices
The place to start with SPI is to use the SPI master library. The slave will be demonstrated through direct manipulation
of the registers because the SPI library does not implement a slave mode. It will be easier (and necessary) to work with
SPI using the registers for both master and slave when developing new protocols. The following list describes the class
functions associated with the SPI library:
SPI.begin() : This starts the SPI on the Arduino and sets input/output (I/O) of the SPI default
pins.
SPI.end() : This turns off SPI but does not change the pin modes.
SPI.setBitOrder() : This passes LSBFIRST or MSBFIRST . The master and slaves must be set
the same for proper communication, and in most cases this is arbitrary. Some hardware will
require a specific bit order, so you should reference a data sheet when using the Arduino with
SPI hardware that cannot be configured.
SPI.setClockDivider() : The Arduino is cable of running at several different speeds by setting
a divider of the main clock. This is useful when connecting devices that cannot operate at
the Arduino maximum speed. Increasing the clock divider lowers the clock speed and is also
useful for troubleshooting connections, by preventing noise or crosstalk on the line from being
sampled as a data. The changes in clock speed can correct for lines that have high-capacitance
issues. Table 10-2 lists the available options that can be set.
the slave devices must be capable of running at the end clock speed of the master. if the clock is too fast,
the slave devices may attempt to read the clock and data but will fail.
Note
 
 
Search WWH ::




Custom Search