Hardware Reference
In-Depth Information
Also, because SPI are serial devices, bits are sent one at a time. Because of this,
you have to know if the device is expecting the most-signii cant bit i rst or the
least-signii cant bit i rst. Data is normally shifted out with the most signii cant
bit i rst.
One last coni guration is the clock speed. The clock is generated by the mas-
ter, and as such, it is the master that dei nes the speed of the bus. Most compo-
nents have a maximum speed coni guration; creating a clock signal above this
frequency results in corrupted data.
Communications
SPI is a master/slave protocol, and as such, the master initiates communication
with a slave. To do this, it pulls the slave's SS pin low (while maintaining any
other SS wires high). This tells the slave that it is being addressed.
To communicate, the slave requires a clock signal, which will be generated by
the master. Each clock pulse results in a bit of data being transmitted; however,
some sensors (like the DHT-11 used later in this topic) require a small timeframe
in which the conversion will be made. If this is required, the master must not
initiate the clock until the slave has had time to complete the conversion.
When the clock signal is generated, both the master and slave are free to com-
municate at the same time. In reality both devices do communicate at the same
time; the master transmits on the MOSI line, and the slave listens to that line.
At the same time, the slave transmits on the MISO line, and the master listens
to that line. Both happen at the same time, but some devices do not require
meaningful data to be received; a slave device that transmits only data receive
data from the master but it ignores all information sent to it.
When the master i nishes, either sending the data it requires or retrieving
data, it normally stops the clock signal and deselects the slave.
Arduino SPI
The SPI bus on the Arduino is an exception compared to most other ports. On
select Arduinos, the SPI bus is present as a dedicated header—the ICSP header,
as shown in Figure 7-2.
The ISCP header has several uses, including bypassing the Arduino boot-
loader to program the microcontroller directly, (ISCP is short for In-Circuit
Serial Programming), but this is out of the scope of this topic.
The ISCP port also normally exposes the SPI bus, depending on models.
The Arduino Uno, the reference model of the Arduino family, uses pin 11 and
ICSP-4 for the SPI MOSI signal. These pins are duplicates; they are electrically
 
Search WWH ::




Custom Search