rising or falling edge of the clock, per the circuitry
inside the slave device. A second data signal is
used as the master input signal, also called the
Master Input Slave Output (MISO). As the master
clocks the data out, it also clocks the data into its
own buffer. Therefore, the slave must have its data
ready to send when the master starts clocking.
The only way the slave can determine that the
master is going to start sending is to monitor its
Chip Select (CS) or slave select (SS) line to see
whether the master has pulled it low. When your
setup has only one slave, it is still a good practice to
use the CS line.
The CS or SS line is the key to having more
slaves connected to a single master. The master
will pull the CS line low for the slave it wants to talk
to and, when the communication is done, the
master pulls that CS high and then pulls the CS line
low of the next slave to talk to. This allows multiple
slaves to share the same set of clock and data lines.
Figure 3 shows a single slave and Figure 4 shows
■ FIGURE 4.
USING SPI WITH THE
PICBASIC PRO COMPILER
The microEngineering Labs PICBASIC PRO compiler
simplifies SPI down to a single command. Many PIC
MCUs have a hardware SPI peripheral built in, so the
communication can happen in the background while the
software is doing something else. The PICBASIC PRO
method uses a "bit banging" or "firmware" implementation
of SPI. This prevents the software from multitasking during
SPI communication. The firmware method allows you to
use SPI on any PIC MCU. The small eight-pin PIC12F683
MCU doesn't have a SPI peripheral, so the PICBASIC PRO
method makes sending SPI from this small chip very easy.
However, I went the other direction and used a larger
chip than the normal 20 pin PIC16F690 that I have used
in previous articles. In this month's project, I use a 28 pin
PIC16F870. The reason for this has less to do with the
chip than the development board.
PIC16F870 is a 28 pin part in this family that works with
The main reason I selected this board over the
PIC16F690 is the six pin header on the side labeled
"PICkit Serial." This six pin header is designed for serial
communication to Microchip's PICkit Serial Analyzer tool.
The tool also works as a great connection header to the
PICkit Serial SPI Demo Board shown in Figure 1. With a
simple six pin cable that I had in my pile of lab extras,
I could easily connect the two boards together. The
microcontroller connections for this header come from
the PORTC pins of the 28 pin socket, per the schematic
in Figure 6.
The PIC16F870 doesn't have an internal oscillator
option, but the development board has the circuitry
included for an external oscillator. I added a three pin
socket and then plugged in a three pin resonator with
capacitors built in. I ran the project at 4 MHz, which is the
■ FIGURE 5. PICkit 2 28-pin Development Board.
The development board I used is shown in Figure 5.
It is a PICkit 2 board that you can purchase separately.
You get one fully
populated board with
a PIC16F886 MCU,
and then two blank
boards. The PICBASIC
PRO sample version
doesn't support the
PIC16F886, but it
does support the
PIC16F87X parts. The
■ FIGURE 6. Six-Pin
March 2009 83