Skip to main content

Welcome to a Grasp lesson

Create a free account to keep studying and create your own study path.

Lesson 31

Synchronous vs. Asynchronous Communication

Recommended resources

Hello! Welcome to the first lesson in our module on synchronous communication protocols.

In the previous module, we built a robust, interrupt-driven UART driver. You learned how to handle continuous data streams and even how to manage communication errors. A key takeaway was that many issues in asynchronous communication, like framing errors, arise from timing discrepancies. The entire system relies on both devices agreeing on a baud rate and maintaining very precise internal clocks.

Today, we address the learning outcome: Explain the differences between synchronous (SPI, I2C) and asynchronous (UART) communication. We will explore a different communication philosophy that eliminates these timing ambiguities by using a shared clock signal. Understanding these fundamental trade-offs is crucial for any embedded engineer tasked with selecting the right protocol for a job, a common requirement in automotive and other professional settings.

1. The "Asynchronous" Challenge: A Recap

Let's start by solidifying our understanding of the "asynchronous" in UART. As you know, it means "no shared clock." The sender and receiver must be configured with identical settings (baud rate, stop bits, etc.) beforehand. The start bit on the RX line signals the receiver to start its internal timer to sample the incoming bits.

This video section provides a great summary of the challenges this approach presents.

How SPI & I2C Work - Communication Protocols | Embedded Systems Explained

The video 'How SPI & I2C Work' by TheFabytm starts by clearly articulating the main drawbacks of UART, which serves as a perfect motivation for why we need synchronous protocols.

Watch the first part of the video from the beginning until 01:18. Focus on the two main drawbacks discussed: the implications of being asynchronous and the limitation to two devices.

As the video explains, the two main disadvantages of asynchronous communication are:

  1. Synchronization Dependency: Both devices must have highly accurate clocks and be pre-configured to the exact same baud rate. Any significant deviation can lead to misinterpretation of data (framing errors).
  2. Point-to-Point Limitation: UART is inherently designed for communication between only two devices. Connecting multiple devices to the same RX/TX lines is not practically feasible without complex external hardware.

2. The Synchronous Solution: A Shared Clock

Synchronous protocols solve the timing problem in a simple yet powerful way: the master device generates a clock signal on a dedicated wire, which it shares with all slave devices on the bus.

  • Asynchronous: The timing is implied. "Start now and sample every N microseconds."
  • Synchronous: The timing is explicit. "Here is a clock pulse. On this edge, the data bit is valid. Read it now."

This fundamental difference is easiest to see visually.

Synchronous (SPI) vs. Asynchronous (UART) Timing
This diagram illustrates the core difference between synchronous and asynchronous protocols. **SPI (top)** has a dedicated clock (CLK) line that dictates exactly when to read the data line. **UART (bottom)** has no clock; it uses a start bit to initiate a timing sequence for sampling the data on the transmit (TX) line.

With a shared clock, the devices no longer need perfectly matched internal oscillators for communication. The slave simply listens for the clock edge from the master to know when to read or send data. This allows for much higher data rates and greater reliability.

The two most common synchronous protocols you will use are the Serial Peripheral Interface (SPI) and the Inter-Integrated Circuit (I2C) protocol.


3. An Overview of SPI, I2C, and UART

Now let's get a high-level view of how all three protocols—our familiar UART and the new SPI and I2C—operate and compare. The following video provides an excellent, detailed walkthrough.

I2C, SPI, UART - In Depth Embedded Protocols!

The video 'I2C, SPI, UART - In Depth Embedded Protocols!' from hoff._world offers a comprehensive comparison that is perfect for this lesson. We'll watch the sections on each protocol to understand their mechanics.

Please watch the following three segments from the video: SPI (1:31 - 9:36): Pay close attention to the Master-Slave paradigm and the function of the four main wires: MOSI, MISO, CLK, and Chip Select (CS). I2C (11:26 - 18:12): Note how I2C achieves multi-device communication with only two wires (SDA and SCL) by using a device addressing scheme. UART (19:53 - 26:26): This section will serve as a review, but it's useful to see it presented in direct contrast to the other two protocols. Notice the emphasis on the pre-agreed baud rate.

Let's break down the key characteristics you just saw:

UART (Asynchronous)

  • Wires: 2 wires (TX, RX).
  • Topology: Point-to-point (two devices only).
  • Clock: None. Relies on start/stop bits and a pre-agreed baud rate.
  • Communication: Full-duplex (can transmit and receive simultaneously).

SPI (Synchronous)

  • Wires: 4 wires minimum (SCLK, MOSI, MISO, CS). Requires one additional CS pin for each extra slave device.
  • Topology: Master-Slave. One master controls multiple slaves.
  • Clock: Yes. The master provides the SCLK signal to all slaves.
  • Communication: Full-duplex. Data is shifted out on MOSI and shifted in on MISO at the same time.
  • Key Feature: Very high speed, simple protocol logic, but requires more pins.

I2C (Synchronous)

  • Wires: 2 wires only (SCL, SDA) for all devices.
  • Topology: Master-Slave, and even supports multiple masters.
  • Clock: Yes. The master provides the SCL clock signal.
  • Communication: Half-duplex. Devices share a single data line (SDA), so they must take turns transmitting and receiving.
  • Key Feature: Uses a 7-bit addressing scheme to select which slave the master talks to. This allows many devices on the bus with minimal pins, but the protocol overhead makes it slower than SPI.

4. A Direct Comparison

To truly master this topic, it's helpful to see the characteristics laid out side-by-side. The following reading provides a detailed analysis and a concise comparison table.

I2C vs SPI vs UART: A Comprehensive Comparison

The article 'I2C vs SPI vs UART: A Comprehensive Comparison' from Wevolver provides an excellent summary of the differences, which will help consolidate what we've learned.

First, read the section 'Key Differences and Comparative Analysis' to get a detailed narrative on the trade-offs. Then, focus on the table in the section 'Comparison in a Nutshell'. This table is an invaluable reference.

Here is a summary of the most critical distinctions for an embedded engineer:

Feature UART SPI I2C
Synchronicity Asynchronous Synchronous Synchronous
Clock No dedicated clock line Master-generated clock (SCLK) Master-generated clock (SCL)
Pin Count 2 (TX, RX) 4+ (SCLK, MOSI, MISO, CS). +1 pin per slave. 2 (SCL, SDA) for the entire bus.
Speed Slowest Fastest Medium
Duplex Full-Duplex Full-Duplex Half-Duplex
Device Selection N/A (point-to-point) Dedicated Chip Select (CS) line per slave 7-bit or 10-bit address sent on the data line
Common Use Case PC serial ports, GPS modules, Debugging SD cards, High-speed ADCs, Display controllers Temp sensors, EEPROMs, Real-time clocks, LCDs
Complexity Simple protocol, but requires clock tuning Simple hardware protocol, pin-hungry More complex protocol (addressing, ACKs), pin-efficient

Conclusion

You have now learned the fundamental theory behind the three most important serial communication protocols in embedded systems. This knowledge is not just academic; it directly influences design decisions in professional projects. Need to read a high-resolution imaging sensor at a high frame rate? SPI is your answer. Need to orchestrate ten different low-speed sensors on a crowded PCB where pins are scarce? I2C is the perfect tool. Need a simple, reliable way to print debug messages to your PC? UART is the go-to.

Key Takeaways:

  • Asynchronous (UART) communication has no shared clock and relies on pre-agreed timing (baud rate), making it susceptible to timing errors but simple for point-to-point links.
  • Synchronous (SPI, I2C) communication uses a master-generated clock signal for robust, high-speed data transfer.
  • SPI is the fastest but uses the most pins, making it ideal for high-throughput, performance-critical peripherals.
  • I2C is a trade-off: it's slower than SPI but extremely pin-efficient, allowing many devices to share a two-wire bus using an addressing scheme.

Preview of the Next Lesson:
With this theoretical foundation in place, we're ready to get our hands dirty. In the next lesson, you will configure the SPI peripheral on your STM32 in master mode and manage the chip select (CS) line for a slave device. This is the first practical step toward communicating with high-speed external components.