Week 11

Networking and Communications

  • Send a message between two projects

Networking and Communications

April 24, 2025

Networking and Communications

Communication protocols are rules that allow the exchange of information between devices connected to a network. Their goal is to enable devices to communicate with each other efficiently, securely, and reliably. Below are some of the most popular communication protocols in embedded systems.

INTRODUCTION

Communication protocols are rules that allow the exchange of information between devices connected to a network. Their goal is to enable devices to communicate with each other efficiently, securely, and reliably. Below are some of the most popular communication protocols in embedded systems.

I2C

I2C communication only uses two wires to transmit information between devices.


I2C is a serial communication protocol, so data is transferred bit by bit along a single wire (the SDA line). I2C is synchronous, so the output of bits is synchronized to the sampling of bits by a clock signal shared between the master and the secondary. The clock signal is always controlled by the master.

With I2C, data is transferred in messages. Messages are broken up into frames of data. Each message has an address frame that contains the binary address of the slave, and one or more data frames that contain the data being transmitted. The message also includes start and stop conditions, read/write bits, and ACK/NACK bits between each data frame:

More information in the following link.

SPI

Devices communicating via SPI are in a master-secondary relationship. The master is the controlling device (usually a microcontroller), while the secondary (usually a sensor, display, or memory chip) takes instruction from the master. The simplest configuration of SPI is a single master, single secondary system, but one master can control more than one secondary.


SPI can be set up to operate with a single master and a single secondary, and it can be set up with multiple secondary controlled by a single master.

More information in the following link.

UART

Only two wires are needed to transmit data between two UARTs. Data flows from the Tx pin of the transmitting UART to the Rx pin of the receiving UART.
UARTs transmit data asynchronously, which means there is no clock signal to synchronize the output of bits from the transmitting UART to the sampling of bits by the receiving UART. Instead of a clock signal, the transmitting UART adds start and stop bits to the data packet being transferred. These bits define the beginning and end of the data packet so the receiving UART knows when to start reading the bits.


When the receiving UART detects a start bit, it starts to read the incoming bits at a specific frequency known as the baud rate. Baud rate is a measure of the speed of data transfer, expressed in bits per second (bps). Both UARTs must operate at about the same baud rate. The baud rate between the transmitting and receiving UARTs can only differ by about 10% before the timing of bits gets too far off.
UART transmitted data is organized into packets. Each packet contains 1 start bit, 5 to 9 data bits (depending on the UART), an optional parity bit, and 1 or 2 stop bits:

More information in the following link.

Comparison table between I2C, SPI and UART

Protocol Characteristics Advantages Disadvantages
I2C
  • Two lines: SDA and SCL
  • Up to 127 slave devices
  • Speeds: 100 kbps, 400 kbps, 1 Mbps
  • Only requires two wires
  • Supports multiple masters and secondary
  • Data reception confirmation (ACK/NACK)
  • Slower speed compared to SPI
  • Frame size limited to 8 bits
  • More complex hardware than SPI
SPI
  • Four lines: MOSI, MISO, SCLK, SS
  • Synchronous and full-duplex communication
  • High transfer speed (up to 10 Mbps)
  • Flexibility in data size
  • Simple hardware interface
  • Requires more pins than I2C
  • Does not support hot-swapping
  • Only supports one master device
UART
  • Asynchronous communication
  • Two lines: TX and RX
  • Speeds: 110 bps to 230.4 kbps
  • Full-duplex communication
  • Does not require external clock
  • Error checking with parity bit
  • Does not support multi-slave or multi-master configuration
  • Packet size limited to 9 bits
  • Not suitable for high-speed communication

Communication Protocol

We used UART, a basic and reliable protocol that only requires a TX pin, RX pin, and a shared ground (GND). Both boards communicated at 9600 baud. Commands were sent as single ASCII characters: