

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. 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. These two properties work together to define when the bits are output and when they are sampled. The clock signal in SPI can be modified using the properties of clock polarity and clock phase. For example, in UART communication, both sides are set to a pre-configured baud rate that dictates the speed and timing of data transmission. There are also asynchronous methods that don’t use a clock signal. SPI communication is always initiated by the master since the master configures and generates the clock signal.Īny communication protocol where devices share a clock signal is known as synchronous. SPI is a synchronous communication protocol. One bit of data is transferred in each clock cycle, so the speed of data transfer is determined by the frequency of the clock signal. The clock signal synchronizes the output of data bits from the master to the sampling of bits by the slave. *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. SS/CS (Slave Select/Chip Select) – Line for the master to select which slave to send data to. SCLK (Clock) – Line for the clock signal. MISO (Master Input/Slave Output) – Line for the slave to send data to the master. MOSI (Master Output/Slave Input) – Line for the master to send data to the slave.

The simplest configuration of SPI is a single master, single slave system, but one master can control more than one slave (more on this below). The master is the controlling device (usually a microcontroller), while the slave (usually a sensor, display, or memory chip) takes instruction from the master. Start and stop conditions define the beginning and end of each packet, so the data is interrupted during transmission.ĭevices communicating via SPI are in a master-slave relationship. With I2C and UART, data is sent in packets, limited to a specific number of bits. Any number of bits can be sent or received in a continuous stream. One unique benefit of SPI is the fact that data can be transferred without interruption. For example, SD card reader modules, RFID card reader modules, and 2.4 GHz wireless transmitter/receivers all use SPI to communicate with microcontrollers. SPI is a common communication protocol used by many different devices. The following diagram shows the serial transmission of the letter “C” in binary (01000011): In serial communication, the bits are sent one by one through a single wire. 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): The bits of data can be transmitted either in parallel or serial form. 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. Bits are transferred from one device to another by quick changes in voltage. 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. Parallel CommunicationĮlectronic devices talk to each other by sending bits of data through wires physically connected between devices. SPI, I2C, and UART are quite a bit slower than protocols like USB, ethernet, Bluetooth, and WiFi, 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. In the next article, we’ll discuss UART driven communication, and in the third article, we’ll dive into I2C. In this series of articles, we will discuss the basics of the three most common protocols: Serial Peripheral Interface (SPI), Inter-Integrated Circuit (I2C), and Universal Asynchronous Receiver/Transmitter (UART) driven communication.įirst, we’ll begin with some basic concepts about electronic communication, then explain in detail how SPI works. Luckily for us, there are only a few communication protocols we need to know when building most DIY electronics projects. In electronics, these languages are called communication protocols. Both sides need to speak the same language. Communication between electronic devices is like communication between humans.
