GETTING STARTED WITHPICs
THE LATEST IN PROGRAMMING MICROCONTROLLERS
■ BY CHUCK HELLEBUYCK
WE WERE “LUCKY” ENOUGH TO GET ANOTHER TWO INCHES OF SNOW here
in Michigan, so its been easy to stay trapped inside at my computer cranking
out another project to help you get started programming with Microchip
PICs. In my January column, I described the I2C form of serial communication.
This month, I am covering its cousin — the Serial Peripheral Interface or
We were “lucky” enough to get another two inches
of snow here in Michigan, so its been easy to stay
trapped inside at my computer cranking out another
project to help you get started programming with
Microchip PICs. In my January column, I described the I2C
form of serial communication. This month, I am covering
its cousin — the Serial Peripheral Interface or SPI
communication. I'll perform the same function and
■ FIGURE 1. Microchip Technology’s PICkit Serial SPI Demo Board.
■ FIGURE 2. SPI Signal Formats.
communicate with a serial EEPROM as in my January
column, but this could easily be a temperature sensor, an
external Analog-to-Digital Converter (ADC), a Digital-to-Analog Converter (DAC), digital potentiometer,
programmable gate array, or an eight-bit I/O expander.
In fact, all of these items are included on the Serial SPI
Demo Board you can get from microchipDIREC T
( www.microchipdirect.com; see Figure 1).
Many chips offer SPI capability, including PIC
microcontrollers (MCUs). The SPI bus operates in a
master-slave arrangement. The master supplies the
clock and data to the slave. The master can also have
a third line for receiving and then a fourth line for
controlling which slave to talk to on the bus. This is
why the SPI bus is sometimes referred to as a "four-wire" serial bus. The SPI bus is not really a true
standard with a platform agreed to by an
international committee like I2C. This leaves the
SPI bus open to interpretation by the maker of the
slave device. It is critical that you read through the
datasheet for the slave device you are using. Some
may want the data to clock in on the rising edge
while others may want to clock in on the falling edge
of the clock signal. The thing you'll notice most — if
you've worked with digital chips for years — is that
SPI looks a lot like the old-fashioned method of
clocking data into a shift register.
■ FIGURE 3. Single Slave.
The master SPI signal is essentially a clock and
data output signal, also called the Master Output
Slave Input (MOSI) signal. The clock can idle in a
low state or a high state. Both are shown in Figure 2.
The data output can be sent the Least Significant Bit
(LSB) first or the Most Significant Bit (MSB) first (also
shown in Figure 2). The data is shifted in on the