The SPI communication protocol operates in full-duplex synchronous mode, enabling connectivity between MCUs and secondary modules such as OLED displays, Electronically Erasable Programmable Read-Only Memory (EEPROM), compasses, etc. Figure 1 represents a typical SPI bus, where there is a master module, a slave module, a clock line (SCLK) to establish synchronicity between the master and slave, two data lines: Master Out Slave In (MOSI) and Master In Slave Out (MISO), and a Slave Select (SS) line.

Figure 1: Bus

To use the SPI communication protocol, both the master and slave must be SPI enabled. The arrowheads on the SCLK, MOSI, and SS lines indicate that the master controls the timing for communication, transmitting data to the slave, and selecting the slave, respectively, while the arrowhead on the MISO line indicates that the slave controls transmitting data to the master.

Figures 2 to 5 represent an example of SPI communication between a master (MCU) module and a slave (OLED-SSD1351) module.

Figure 2: Part A
  • Idle: Before SPI communication takes place, all four lines, SCLK, MOSI, MISO, and SS, remain pulled HIGH, implying that the system is Active-LOW.
  • SS: The SS line is pulled LOW, where the master selects the slave, marking the beginning of communication.
  • command byte: Transmission of the command byte begins with the SCLK line pulled LOW in conjunction with the MOSI line either remaining HIGH or pulled LOW, depending on the value of the MSB. In this case, it is 1. The master transmits the command byte 0b11111101 to the slave, as per the manufacturer data sheet of the slave, to set the command lock. All 8 bits are transmitted from the master to the slave, corresponding to the clock pulses.
  • Idle: All three lines, SCLK, MOSI, and MISO, are pulled HIGH.
  • SS: The SS line is pulled HIGH, where the master de-selects the slave, marking the end of communication.
Figure 3: Part B
  • Idle: All four lines, SCLK, MOSI, MISO, and SS, remain pulled HIGH.
  • SS: The SS line is pulled LOW.
  • data byte: Transmission of the data byte begins with the master transmitting 0b00010010 to the slave to unlock the OLED driver IC MCU interface from entering commands.
  • Idle: All three lines, SCLK, MOSI, and MISO, are pulled HIGH.
  • SS: The SS line is pulled HIGH.
Figure 4: Part C
  • Idle: All four lines, SCLK, MOSI, MISO, and SS, remain pulled HIGH.
  • SS: The SS line is pulled LOW.
  • command byte: The master transmits the command byte 0b11111101 to the slave to set the command lock.
  • Idle: All three lines, SCLK, MOSI, and MISO, are pulled HIGH.
  • SS: The SS line is pulled HIGH.
Figure 5: Part D
  • Idle: All four lines, SCLK, MOSI, MISO, and SS, remain pulled HIGH.
  • SS: The SS line is pulled LOW.
  • data byte: Transmission of the data byte begins with the master transmitting 0b10110001 to the slave to make commands A2, B1, B3, BB, BE, and C1 accessible.
  • Idle: All three lines, SCLK, MOSI, and MISO, are pulled HIGH.
  • SS: The SS line is pulled HIGH.

Note that in this particular case, the SSD1351 module does not reply back to the master, which is why the MISO line remains HIGH. In such a case, the master does not read data byte(s) from the slave, which in turn means that there is no need for a MISO line. In some other SPI-enabled modules, the MISO line is used.