Hardware Reference
In-Depth Information
The basic process for communicating with an SPI device is as follows:
1. Set the SS pin low for the device you want to communicate with.
2. Toggle the clock line up and down at a speed less than or equal to the
transmission speed supported by the slave device.
3. For each clock cycle, send 1 bit on the MOSI line, and receive 1 bit on the
MISO line.
4. Continue until transmitting or receiving is complete, and stop toggling
the clock line.
5. Return the SS pin to high state.
Note that on every clock cycle a bit must be sent and received, but that bit does
not necessarily need to mean anything. For example, later in this chapter you will
use a digital potentiometer in a scenario in which the Arduino will send data but
does not need to receive anything back from the slave. So, it will clock data out
on the MOSI pin and will just ignore anything that comes back on the MISO pin.
ComparingSPItoI 2 C
Many kinds of devices, including accelerometers, digital potentiometers, and
displays, are available in both SPI and I 2 C versions. So how do you decide?
TableĀ 9-3 lists some of the trade-offs between I 2 C and SPI. Ultimately, which
one you choose to use will depend on what you believe is easier to implement,
and best suited for your situation. Most beginners find that they can get SPI
working more easily than I 2 C.
Table 9-3: SPI and I2C Comparison
SPI ADVANTAGES
I 2 C ADVANTAGES
Can operate at higher speeds
Requires only two communication lines
Generally easier to work with
Built-in Arduino hardware support
No pull-up resistors needed
Built-in Arduino hardware support
CommunicatingwithanSPIDigitalPotentiometer
Now that you've got all the basics down, it's time to actually implement what
you've learned. You'll start by controlling LED brightness using a digital poten-
tiometer (a DigiPot for short). Specifically, you'll use the Microchip MCP4231
103E Digital Potentiometer IC. (Several versions of this chip are available, each
with different potentiometer resistance values.) When looking for an integrated
Search WWH ::




Custom Search