Hardware Reference
In-Depth Information
Introducting SPI
Serial data connections have been the backbone for computer communication
systems for decades. Reliable and sufi ciently fast for most devices, they have
been used to communicate with modems, IC programmers, and computer-to-
computer communications for most of computing's history. They use few wires
compared to other communications systems and are generally robust—qualities
that are useful for embedded systems and peripherals.
Serial communications are also used deep inside embedded systems where
space is critical. Instead of connecting a device to a 32-bit data bus, a simple
temperature sensor can, instead, be connected to the microcontroller via just a
few wires. It makes design simpler, cheaper, and more efi cient.
Although serial connections have a lot of advantages, they also have disad-
vantages. Having a modem and a programmer requires a computer with two
serial ports; a serial port cannot (easily) handle multiple devices. One serial
port, one device. This is the same for microcontrollers and microprocessors;
most devices have at least one serial port, but it is difi cult to i nd a device with
more than three RS-232 serial ports. Also, more ports mean more software—and
more tasks used to check the serial buffers. Also, a modem might be used for
long periods of time, but a chip programmer will be used for just a minute or
two, tying up a serial port for a single task that is rarely run.
SPI Bus
To allow multiple devices to be used on a single serial port, the SPI bus was
created. SPI is short for Serial Peripheral Interface and is indeed an interface to
devices, using a synchronous serial line capable of full-duplex communication
(meaning that both devices can send and receive at the same time).
SPI is a master/slave protocol; one master communicates with one or more
slaves. Communication is made with only one slave at a time; to communicate
with another slave, the master must i rst stop communicating with the i rst slave.
Slaves cannot “talk” on the network without being instructed to by the master.
To connect and talk to a slave, a master requires at least four wires. The “Master
Out-Slave In” (MOSI) and “Master In-Slave Out” (MISO) wires are used for data
communication; SCLK is a serial clock that regulates the speed of the commu-
nication; and SS (short for Slave Select) is used to select the peripheral. It's not
uncommon to see SS referred to as CS (for Chip Select) in some documentation.
SS is a wire that “selects” a slave on a logical zero. The MOSI, MISO, and
SCLK wires are connected to every device on the SPI bus, and devices listen
only to the master and communicate if their SS wire is set to active low. This
allows for several slaves to be connected to a master on the same network. A
typical SPI bus is shown in Figure 7-1.
 
Search WWH ::




Custom Search