Embedded System Communication Protocols
Introduction
​
Communication is simply the transmitting (sending) and receiving data from source to location respectively. As we all know, communication is a very important factor for human existence. It helps us in many ways from sharing ideas or information to getting huge task done easily through connecting with others, we literally need to communicate to survive.
​
As we find communication essential as humans, so do machines. They need to communicate with us humans and also with themselves to make operations and functionality optimum. In our world today, where talks on connected devices is a trend, we need to really understand how these devices can be connected looking at the different methods ranging from wired to wireless.
​
Here, we will look at the different communication protocols used by embedded device for Machine-to-Machine (M2M) and Internet of things (IoT) applications. We will look the functions, applications, advantages and disadvantages of the different protocols. In our subsequent tutorials, we will practicalize using these communication protocols with different microcontrollers such as the Arduino, STM32, 8051, etc. Although in this course, we'll use the Arduino as our reference controller to explain some concepts.
Methods of Communication
​
There are hundreds of communication protocols available for exchange of data between
embedded devices by using both wired and wireless pathways. We will broadly classify
these protocols into two categories. These are:
-
Parallel communication.
-
Serial communication.
Parallel Communication Protocol
Parallel communication transfers multiple bits simultaneously using large chunks of 0s and 1s. Because they transfer multiple bits at once, they transfer data at high speed making them very useful for short distance high speed data transfer.
​
Although it's suitable for fast applications, it's drawbacks include: cost of transfer channel e.g. multiple wires, it also has distance limitations; up to several meters. So, if you wish to carry out long distance data transfer, we use the next protocol, which is the serial communication protocol.
Serial Communication Protocol
Serial communication allow us to send off one bit at a time through a communication channel or a computer bus. Because it sends a single bit per time, it is slower than the parallel communication. However, it is simpler to implement, uses fewer pins and less communication channels. Many serial communication protocols work on as less as two wires.
In embedded systems, since we do not have luxury of microcontroller pins at our disposal, serial communication is often preferred over parallel communication since the trade-off for transfer speed doesn't hurt much. On that note we will focus more on serial protocols rather than parallel.
Before we continue, these communication protocols can also be classified into two categories which are synchronous and asynchronous. Remember, digital systems operates with bits (0s and 1s). On that note, a clock is required to generate these signals. In this case, we can say the the system is communicating synchronously. In asynchronous communication, the clock is not present, instead of the methods are used to generate the pulse.
​
For practical applications, the synchronous communication is more reliable but requires extra connection wires. The asynchronous communication on the other hand will save you a some pins.
Wired serial communication
As we heard earlier, serial communication can be wired. Some peripherals such as sensors might connect to the main controller through serial. Some standard communication protocols under wired serial include: UART, SPI, 12C, Ethernet.
UART
Universal Asynchronous Receiver Transmit (UART for short) is serial protocol that allows communication between two devices. Hence, two arguments which represents both the directions of data are required.
The connected devices each have their transmitter and receiver. They send data as a series of pulses serially. A pulse can represent one bit of data. This process requires only one cable to send data plus the ground reference cable. The transmitter of the master (say an Arduino) is connected with the receiver of the slave (peripheral).
CP2102 UART module.
Factors to consider in UART communication:
​
Baud rate
This is the rate of transmission in the channel. Generally, the default baud rate is
9600 bps (baud per second). Meaning, data is transferred at the rate of 9600 bits per second.
​
Data frame
In UART, data is sent in a data frame which is known as packets. This frame consist of the
main data together with some information such as the transmission speed, data length and the start and stop bits to ensure accurate communication.
​
Advantages of UART
-
UART has low hardware complexity.
-
Doesn't require software addressing.
​
Disadvantages of UART
-
UART only supports communication between two devices.
-
The data rate is fixed.
​
Application
-
The Arduino for example uses UART communication to upload code from computer to board or send data from board to serial monitor on the computer.
SPI
Serial Peripheral Interface (SPI for short) is an asynchronous serial data protocol. Usually, SPI connection is handled by a microcontroller that has other peripheral devices. For example, in Arduino UNO, the ATmega328 supports SPI communication.
It has four lines and are common for all peripheral devices. These are:
-
MISO (Master In Slave Out) - This line sends data to the Arduino.
-
MOSI (Master Out Slave In) - This line takes output from the master and gives it as input to slave.
-
SCK (Serial Clock) - Produces the clock pulse. Used to synchronize data from Arduino.
-
SS (Slave Select) - Used by Arduino go enable or disable a peripheral device. When SS pin is LOW (0). peripheral starts communicating with Arduino then ignores Arduino when SS pin is HIGH (1).
Advantages of SPI
-
With SPI, hardware interfacing is straightforward.
-
Flexible for bit transmission.
-
Much faster than asynchronous serial communication.
-
Allows connection of multiple slaves.
-
Permits full duplex communication
-
Does not need any transceiver.
​
Disadvantages of SPI
-
SPI requires more pins.
-
Supports only one master device.
-
Nodes can't be added dynamically.
-
SPI protocol doesn't have error checking mechanism.
I2C
Inter Integrated Circuits (I2C for short) is a serial communication protocol mainly used
to communicate with various sensor devices that can fetch data to the microcontroller such
as Arduino.
I2C module for LCD.
Advantages of I2C
-
I2C is more flexible to work with.
-
Less complexity.
-
Chip addressing can be used to easily add components to the bus.
-
Has better error handling mechanism.
-
Readily adaptable.
​
Disadvantages of I2C
-
I2C always has an address conflict due to chip addressing.
-
Has limited speed.
-
Requires more space.
Ethernet
Ethernet is the standard way to connect computers on a network over a wired connection.
Embedded devices can also take advantage of this feature, for example Arduino, Raspberry pi and other embedded development boards have ethernet port either onboard or through shields. With these you can connect different boards together or connect the board to the internet via a router. The Arduino can act either as a server that host and accepts incoming network connections or as a client that enables outgoing connections. You need a special library to able to use the ethernet functionality of the Arduino.
Arduino Ethernet Shield.
Advantages of Ethernet
-
Comparatively low cost.
-
Requires little maintenance and administration.
-
All nodes have equal privileges.
​
Disadvantages of Ethernet
-
Ethernet receivers don't acknowledge after receiving a package.
-
Not very useful in traffic-intensive projects.
-
It doesn't give priorities to packets.
Wireless Serial Communication
​
We can also use serial communication to transfer data wirelessly without any physical contact with the receiver. The are many wireless protocols out there, but we'll discuss a few here which are: Bluetooth, Wi-Fi, MQTT, and GSM.
​
Bluetooth
Bluetooth is a wireless communication protocol that uses radio waves for transmitting and receiving data. It is low cost and consume less power, making it one of the most commonly used wireless communication protocol. Bluetooth supports IEE802.15.4 and has a frequency range of 2.4GHz. It can work up to 10 meters, making it suitable for short distance wireless communication. Although upgraded versions such as the Bluetooth 4.2 and 5.0 can boast of connectivity distance of 60 and 240 meters respectively.
HC-05 Bluetooth module
They find applications our smart phones and computers and also in various embedded devices such as wireless headsets, speakers, printers, even in cars, etc.
Advantages of Bluetooth
-
Cheap and cost-efficient.
-
Straightforward to install and use.
-
Allows both voice and data transfer.
-
Bluetooth range is higher that that of infrared communication.
-
Low power consumption.
​
Disadvantages of Bluetooth
-
Lower bandwidth (short distance).
-
Lower data security (can be easily hacked).
-
Allows for only two devices to be connected at once.
-
Connections can be lost in certain conditions (interference).
Wi-Fi.
Wireless Fidelity (Wi-Fi for short) is a wireless network protocol based on the IEEE 802.11 family of standards. It uses radio to enable transfer of information between devices. It is the next most common wireless protocol to Bluetooth. It is commonly used for wireless local area networking (WLAN) of devices. Wi-Fi need three components to operates: radio signal, antenna, and router. These are commonly integrated in a module. For example, the Arduino commonly use the ESP8266 UART-Wi-Fi module to enable Wi-Fi access, while some advance boards like the raspberry pi has an onboard Wi-Fi module. Wi-Fi is used to connect 2.4 GHz and 5 GHz devices.
ESP8266 Wi-Fi module.
Wi-Fi finds applications in computer, smart phones, home and small office networks, TVs, printers, smart speakers, wireless router to connect to internet, in smart access points, etc.
​
Advantages of Wi-Fi.
-
Wi-Fi has higher data speed transfer.
-
It has high data transfer security.
-
Gives room for expansion (i.e., multiple connected devices).
-
Wi-Fi is comparably lower in cost.
-
Flexible to use.
-
Provides wider coverage than Bluetooth.
​
Disadvantages of Wi-Fi.
-
Wi-Fi consumes more power.
-
Not suitable for long distance communication.
-
It operates on the 2.4 GHz spectrum which is already crowded with other devices.
-
Wi-Fi speed is slower when compared to wired connection.
MQTT
Message Queuing Telemetry Transport (MQTT for short) is communication protocol suitable for connecting devices with low bandwidth. It plays a major role in Machine-to-Machine (M2M) and Internet of Things (IoT) applications. It is a lightweight publish and subscribe messaging protocol i.e., devices publish and send information as a message broker, making it the best choice for wireless communication involving varying latency.
MQTT client is any device connected to the network using the MQTT library. MQTT is a low-overhead protocol that strongly considers the bandwidth and CPU limitations. It usually runs over TCP/IP. MQTT gateway is an ethernet gateway with modified software to make it support MQTT protocol.
​
Advantages of MQTT.
-
It is highly reliable.
-
Can transfer any type of data.
-
It is time efficient.
-
It can push and subscribe model in power-efficient way.
-
MQTT minimizes network bandwidth.
​
Disadvantages of MQTT.
The main concern with MQTT is the TCP/IP principle it operates with. TCP/IP was originally designed for devices with more memory and processing power, therefor some operation do not really align with the feature the lightweight, power constrained devices connected over MQTT.
​
Issues like:
-
Requiring more handshakes to set up communication line before message exchange which affects long term battery consumption due to increases wake-up time of the device.
-
TCP connected devices tend to keep sockets open for each other with persistent session, adding to power and memory requirements.
-
Centralized broker can limit scale which can affect scalability as there is additional overhead for each device connected to it.
GSM
Global System for Mobile communication (GSM for short) in a standard of communication developed by European Telecommunication Standard Institute (ETSI) to describe the protocols for second-generation (2G) digital cellular networks. GSM uses Time Division Multiple Access (TDMA) for transmitting data.
​
The GSM standard originally described a digital, circuit-switched network optimized for full duplex voice telephony. This expanded over time to include data communications, first by circuit-switched transport, then by packet data transport via General Packet Radio Service (GPRS), and Enhanced Data Rates for GSM evolution (EDGE). Subsequently, the 3GPP developed third-generation (3G) UMTS standards, followed by the fourth-generation (4G) LTE Advanced and the fifth-generation 5G standards.
​
2G uses Compression and Decompression (CODEC) algorithms to compress and multiplex voice data. 2G can hold a large number of calls per amount of bandwidth, and also offer SMS and email services. Ii uses low powered radio signal that requires less battery power.
GSM module
3G was introduced in 2000. It increases data transmission from 144 kbps to 2Mbps. This leads to more bandwidth for smartphones. It also allows simultaneous use of speech and internet data service.
​
4G provides 100Mbps to 1Gbps speed. Another name for 4G is MAGIC which stands for Mobility Support Integrated Wireless Solution. 3G and 4G can be used for IoT applications, but requires constant power supply.
​
5G is the latest standard for broadband cellular networks. It is the planned successor to 4G networks. The main advantage of this new network is that they will have greater bandwidth, giving higher download speed, eventually up to 10 gigabits per second (Gbps), making it very suitable for IoT and machine learning applications. The downsides to 5G is they they operate in short distance and very cotsly to implement.
​
Advantages of GSM
-
GSM improves spectrum efficiency.
-
It provide faster communication compared to the others.
-
Can send and receive large email messages.
-
Has broadband capabilities.
-
It supports international roaming.
-
GSM provides high-speed web service with more security.
​
Disadvantages of GSM.
-
Consumes much power.
-
Requires much more experience to work with.
-
4G modules are not readily available for DIY users.
-
High cost of implementation.
-
Reduced coverage due to losses like penetration loss, attenuation, foliage loss, etc., especially in the case of 5G.
Choosing the right communication protocol for your project.
​
The following factors should be considered:
-
How many devices are to be connected.
-
What data transfer speed is required.
-
The distance between the connected devices.
-
Power consumption.
-
Most importantly your budget for the project.
​
Wired protocol.
-
For communication with sensors, I2C is the most suitable choice.
-
For reliability, then go for SPI protocol.
-
If you wish to connect to the internet, then ethernet is your best shot for wired.
​
Wireless protocol.
-
Bluetooth is very suitable for close range, lower power communication.
-
Wi-Fi is cool if you need to things a little faster and farther apart.
-
If you wish to go a little step up, then GSM comes in handy.
​
Always remember that wireless means more power consumption, cost and complexity, especially for Wi-Fi and GSM.
​
Other popular wireless communication protocols include:
-
Zigbee.
-
Z wave.
-
Thread.
-
RF.
-
6LowPAN.
-
NFC.
-
Lora.