Microcontroller protocols allow electronic devices to communicate with each other. Electronic devices send bits of data that are then processed using microcontroller protocols [1]. In certain scenarios, one protocol may be favored due to its data transmission properties. We will cover the most common microcontroller protocols: Serial Peripheral Interface (SPI), Inter-Integrated Circuit (I2C) and Universal Asynchronous Receiver/Transmitter (UART).
SPI has the ability to continuously send and receive data, without interruption, causing it to have a high data transmission rate. SPI has this ability, because it has separate lines for sending and receiving signals [1]. These advantages allow SPI to be used in many electronic devices such as:
LCD displays
Ethernet
WiFi
Analog to Digital Converters
Real-Time Clocks [2]
Figure 1: An example of a WiFi router using SPI is shown above [6].
It uses four wires to connect slave and master devices as opposed to the two connections needed in I2C and UART protocols [1].
SPI cannot be used when more than one master device is needed. This limits how much can be controlled [1].
SPI does not inform the user that data transmission is working and it has no error checking mechanism, making SPI more difficult to troubleshoot [1].
SPI must be used to communicate between master and slave devices [1]. Not surprisingly, the master device is in control of the slave device. For this reason, the master device is typically a microcontroller because of its ability to provide commands to other devices. The slave device receives the commands from the master, indicating when to perform its function.
SPI can be implemented with one master device and one or more slaves. The example of one master and one slave will be used to explain the operation of SPI.
MOSI - Master Output, Slave Input [1]
The master sends data to the slave in this connection.
MISO - Master Input, Slave Output [1]
The slave sends data to the master in this wire.
SCLK - Serial Clock
This connection allows the master to change the frequency of the clock signal which alters data transmission speed [1].
SS/CS - Slave Select/Chip Select:
This pin allows the master to determine which slave device to communicate with. In some microcontrollers, there are multiple SS pins that can be wired to different slaves, but in other microcontrollers, the same SS pin can be wired to various slaves [1].
Figure 1: The pins connecting the master and slave devices are shown in the image above. This image was taken from Circuit Basics [1].
Unlike SPI, I2C can have numerous master or slave devices connected simultaneously. The ability to have multiple masters increases the functionality of the protocol. I2C also only requires two connectors between master and slave devices [3]. Thus, I2C is best suited for complex systems. Additionally, it is easier to troubleshoot devices using I2C, because it provides the status of data transmission.
OLED displays
Barometric pressure sensors
Gyroscopes
Accelerators [3]
Figure 2: This shows the an Arduino OLED display using I2C protocol [4].
One limitation of I2C is that a continuous stream of data cannot be sent or received. The maximum data size sent at one time is 8 bits. For this reason, data cannot be transmitted as fast as SPI [3].
The setup of I2C is much more complex [3]. For fewer devices and functions of the circuit, other protocols are easier to use.
In the I2C protocol, devices transfer data through binary messages that are divided into frames.
Address Frame
This frame distinguishes which slave the master will communicate with at a given time [3].
Start Condition
1 indicates that data transfer stops just before the serial clock turns off.
Stop Condition
1 indicates that data transfer stops just after the serial clock turns off.
ACK/NACK (Acknowledge/No Acknowledge) Bit
An ACK/NACK bit provides information on if each frame is successfully transmitted. An acknowledge bit is sent if the data transfer is successful [3].
Read/Write Bit
1 when the master device is receiving data, 0 when the master device is sending data [3].
SDA - Serial Data
Two-way transmission of data between the master and slave device occurs in this wire [3].
SCL - Serial Clock
The master controls the frequency of the clock signal, altering the data transmission speed [3].
Figure 3: The data sent in I2C that is called a message. This graphic was retrieved from Circuit Basics [3].
Figure 4: The pin connections of the master and slave devices using I2C protocol is shown above. This image was retrieved from Circuit Basics [3].
Although Universal Asynchronous Receiver/Transmitter (UART) is not a communication protocol, it is a relevant alternative communication method to SPI and I2C. UART is a physical integrated circuit within a microcontroller such as Arduino [5].
A UART is primarily used to send and receive data between 2 devices. Below are some example devices that use UART to connect to microcontrollers like an Arduino. We have used the first two in class!
GPS modules
LCD screens
Bluetooth Modules
RFID Modules
Figure 5: A GPS module connected to an integrated circuit uses UART communication [7].
UART only requires 2 wires but they are bulky compared to USB
Like I2C, UART communication has a bit that tells the user when data is or is not being sent properly. This bit is called the parity bit and it is an advantage to using a UART over SPI
A signal clock is not required but data can only be transmitted 9 bits at a time in a packet
More than 2 devices cannot be connected via a UART which limits the functionality of UART communication. When more devices need to be connected, SPI or I2C could be used [5].
UART communication must occur between two connected UART devices. These devices send data in binary messages called packets which can be broken down into the following parts [5].
Start Bit
The transmitter uses the start bit to inform the receiver to start reading the following bits [5].
Data Frame
This is where the data is stored within the packet. Only 5-9 bits of storage are available.
Parity Bit
The parity bit allows the receiving integrated circuit to check the if the data it received matches the data sent by the transmitting integrated circuit. The receiver counts the number of binary ones in the data frame and represents an odd number with 1 and an even number with 0 [5].
Stop Bit(s)
The stop bit tells switches the voltage between the circuits so there is a pause between each packet of data [5]
Tx - Transmitting pin
UART 1 adds the stop, start, and parity bits to each data frame before sending data in packets from the Tx pin.
Rx - Receiving pin
UART 2 receives the data sent at the Rx pin. Then, it removes the stop, start, and parity bits to read the data frame.
Figure 6: The bits that make up a packet are outlined above. This image was taken from Circuit Basics [5].
Figure 7: The connection between two UART devices is shown. This image was taken from Circuit Basics [5].
[1] Basics of the SPI Communication Protocol. (2018, May 23). Retrieved April 3, 2020, from https://www.circuitbasics.com/basics-of-the-spi-communication-protocol
[2] Embedded Systems Communication Protocols. (2019, August 5). Retrieved April 3, 2020, from http://home.roboticlab.eu/en/iot-open/introduction/introduction_to_iot_communication_and_protocols
[3] Basics of the I2C Communication Protocol. (2017, April 11). Retrieved April 3, 2020, from https://www.circuitbasics.com/basics-of-the-i2c-communication-protocol/
[4] OLED I2C Display Arduino Tutorial. (2017, October 17). Retrieved April 6, 2020, from https://startingelectronics.org/tutorials/arduino/modules/OLED-128x64-I2C-display/
[5] Basics of UART Communication. (2017, April 11). Retrieved April 6, 2020, from https://www.circuitbasics.com/basics-uart-communication/
[6] 2020 SPI LED WiFi Controller Dimmer RF Touch Remote Control WF300 For RGB LED Light Strip DC5V 24V From Kiwilighting, $45.2. (n.d.). Retrieved April 6, 2020, from https://www.dhgate.com/product/spi-led-wifi-controller-dimmer-rf-touch-remote/196751847.html
[7] NEO6MV2 GPS module with active antenna. (n.d.). Retrieved April 6, 2020, from https://nettigo.eu/products/neo6mv2-gps-module-with-active-antenna