Basics of The Spi Communication Protocol
Basics of The Spi Communication Protocol
Basics of The Spi Communication Protocol
The master switches the SS/CS pin to a low voltage state, which activates the slave:
SPI, I2C, and UART are quite a bit slower than protocols like USB,
Ethernet, Bluetooth, and Wi-Fi, but they’re a lot more simple and use less
hardware and system resources. SPI, I2C, and UART are ideal for
communication between microcontrollers and between microcontrollers and
sensors where large amounts of high speed data don’t need to be
transferred.
SERIAL VS. PARALLEL COMMUNICATION
Electronic devices talk to each other by sending bits of data
through wires physically connected between devices. A bit is like
a letter in a word, except instead of the 26 letters (in the English
alphabet), a bit is binary and can only be a 1 or 0. Bits are
transferred from one device to another by quick changes in
voltage. In a system operating at 5 V, a 0 bit is communicated as
a short pulse of 0 V, and a 1 bit is communicated by a short pulse
of 5 V.
The bits of data can be transmitted either in parallel or serial form.
In parallel communication, the bits of data are sent all at the same
time, each through a separate wire. The following diagram shows
the parallel transmission of the letter “C” in binary (01000011):
2. The master switches the SS/CS pin to a low voltage state, which activates the slave:
MOSI (Master Output/Slave Input) – Line for the master to send data to the slave.
MISO (Master Input/Slave Output) – Line for the slave to send data to the master
In practice, the number of slaves is limited by the load capacitance of the system, which reduces the
ability of the master to accurately switch between voltage levels.
2. The master switches the SS/CS pin to a low voltage state, which activates the slave:
The clock signal in SPI can be modified using the properties of clock
polarity and clock phase. These two properties work together to define when
the bits are output and when they are sampled. Clock polarity can be set by
the master to allow for bits to be output and sampled on either the rising or
falling edge of the clock cycle. Clock phase can be set for output and
sampling to occur on either the first edge or second edge of the clock cycle,
regardless of whether it is rising or falling.
SLAVE SELECT
The master can choose which slave it wants to talk to by setting the slave’s
CS/SS line to a low voltage level. In the idle, non-transmitting state, the
slave select line is kept at a high voltage level. Multiple CS/SS pins may be
available on the master, which allows for multiple slaves to be wired in
parallel. If only one CS/SS pin is present, multiple slaves can be wired to
the master by daisy-chaining.
2. The master switches the SS/CS pin to a low voltage state, which activates the slave:
MULTIPLE SLAVES
SPI can be set up to operate with a single master and a single slave, and it
can be set up with multiple slaves controlled by a single master. There are
two ways to connect multiple slaves to the master. If the master has
multiple slave select pins, the slaves can be wired in parallel like this:
If only one slave select pin is available, the slaves can be daisy-chained like this:
2. The master switches the SS/CS pin to a low voltage state, which activates the slave:
The slave can also send data back to the master through the MISO line in serial. The data
sent from the slave back to the master is usually sent with the least significant bit first.
2. The master switches the SS/CS pin to a low voltage state, which activates the slave:
3. The master sends the data one bit at a time to the slave along the MOSI line. The
slave reads the bits as they are received:
4. If a response is needed, the slave returns data one bit at a time to the master
along the MISO line. The master reads the bits as they are received:
2. The master switches the SS/CS pin to a low voltage state, which activates the slave:
ADVANTAGES
No start and stop bits, so the data can be streamed continuously without interruption
Separate MISO and MOSI lines, so data can be sent and received at the same time
DISADVANTAGES
Uses four wires (I2C and UARTs use two)
No acknowledgement that the data has been successfully received (I2C has this)
Hopefully this article has given you a better understanding of SPI. Continue on to part two of
this series to learn about UART driven communication, or to part three where we discuss
the I2C protocol