Contents
1. Introduction: From GPIO to Communication Peripherals
In modern electronic devices, the collaborative operation among various components is of critical importance. When the ESP32 controls LED lights and displays, and monitors the status of buttons and sensors, it is essentially exchanging data with external devices.
Recall the previous experiment of controlling an LED with a button, which realizes simple communication with external devices through GPIO.
However, if we need to exchange data with a display screen or some sensors, the workload will increase significantly. The transmission efficiency of GPIO is limited, which cannot meet the exchange requirements of high frequency and large data volume. Especially when multiple devices are involved, GPIO not only occupies more pins, but also may lead to slow communication speed and even data loss.
At this point, we need to introduce more powerful communication methods, and the ESP32 also provides several communication peripherals, such as UART, I2C and SPI. With the help of these peripherals, we can easily realize communication with the outside world.
2. Basic Concepts of Communication
Before learning about the communication peripherals of the ESP32, we need to first understand some basic communication concepts, which are the key to subsequently learning protocols such as UART, I2C, and SPI.

2.1 Serial and Parallel: Trade-off Between Efficiency and Resources
According to the data transmission mode, communication can be divided into serial communication and parallel communication.


- Serial communication (which transmits data via a single signal line, consumes fewer resources and is suitable for long-distance communication): Data bytes are transmitted sequentially one bit at a time over a single transmission line, which occupies fewer pin resources but has a relatively low speed.
- Parallel communication (in which multiple signal lines transmit data simultaneously, featuring high speed but high resource occupation): Each data bit is transmitted at the same time, which is fast but occupies a lot of pin resources.
2.2 Synchronous and Asynchronous – The Role of the Clock
Depending on whether an additional clock signal is required to coordinate data transmission, communication modes can be categorized into synchronous communication and asynchronous communication:
- Synchronous communication (with clock signals, e. g. I2C, SPI): when transmitting data, an additional clock line is added, and the transmitter and receiver send and receive data synchronously according to the rhythm of the clock.
- Just like a teacher in class calling out a roll call, all the students respond one after another in rhythm to ensure that the information is conveyed in an orderly and error-free manner.
- Asynchronous communication (without clock signals, e. g., UART): the transmitting end and the receiving end agree on the communication rate in advance, but each party independently controls when to send and receive data, with no additional clock signal required.
- It's just like two friends agreeing to "say one word per second" — even without seeing each other, they can correctly interpret the information.
2.3 Simplex / Half-duplex / Full-duplex - Data Transmission Direction
Some communication modes allow simultaneous data transmission and reception, while others require taking turns, and some only support unidirectional transmission. The transmission direction of data determines the interaction mode of communication, which is mainly divided into simplex, half-duplex and full-duplex:
- Simplex (data is only transmitted in one direction): Data is transmitted in only one direction.
- Similar to radio stations, the transmitting end sends out information, and the receiving end can only listen but cannot reply.
- Half-duplex (data can be transmitted in both directions, but only in one direction at the same time): It allows data to be transmitted in both directions, but only permits data transmission in one direction at a given moment, which is equivalent to simplex communication with a switchable direction.
- Similar to a walkie-talkie, it supports both speaking and listening, but not simultaneously.
- Full-duplex (data can be transmitted in both directions simultaneously): It allows data to be transmitted in both directions at the same time. Therefore, full-duplex communication is a combination of two simplex communication modes, which requires both the transmitting and receiving devices to have independent transmitting and receiving capabilities.
- Similar to a phone call, both parties can speak and listen to the other side at the same time.
3. Overview of Main Communication Methods of ESP32
As a powerful microcontroller, the ESP32 integrates a variety of communication interfaces, enabling it to exchange data with various sensors, peripherals, other microcontrollers and even computers. Common communication methods include UART, I2C, SPI and CAN, which are the most frequently used approaches for data exchange with external devices.
3.1 UART (Universal Asynchronous Receiver/Transmitter)
UART is an asynchronous, serial, full-duplex Communication Protocol, suitable for one-to-one communication.

It only requires two wires (TX and RX) to transmit data without the need for an additional clock signal. As long as both parties agree on the baud rate in advance, they can perform transmission and reception simultaneously. The UART protocol controls the data transmission rate via the preset baud rate.
Serial.begin(115200); // Set the baud rate to 1152003.2 I2C (Inter-Integrated Circuit)
I2C is a synchronous, serial, half-duplex Communication Protocol suitable for one-to-many communication.

It transmits data via a clock line (SCL) and a data line (SDA), adopting a master-multislave architecture. It supports multiple devices to share these two lines, thus occupying fewer pins.
3.3 SPI (Serial Peripheral Interface)
SPI is a synchronous, serial, full-duplex Communication Protocol, which is commonly used for high-speed data transmission, such as exchanging data with external devices (sensors, memories, etc.).

It adopts a master-slave architecture with one master and multiple slaves, supporting a plurality of slave devices. Data transmission is carried out via four signal lines, namely the serial clock line SCK, the master output/slave input line MOSI, the master input/slave output line MISO, and the chip select line CS. It allows bidirectional data transmission at the same time, and features a relatively high transmission speed thanks to the clock synchronization mechanism.
3.4 CAN (Controller Area Network)
CAN is a synchronous, serial, full-duplex Communication Protocol, suitable for many-to-many communication scenarios.

It enables multi-device interconnection with only two wires (CAN_H and CAN_L), eliminating the need for a fixed master-slave relationship, and all devices can actively transmit messages. Thanks to its strong anti-interference capability, it is commonly used in automotive and industrial scenarios.
4. Summary of This Chapter
In this chapter, we start from the simplest GPIO communication and gradually get to know more efficient communication methods.
- Serial vs. Parallel: Serial interface saves pins and is suitable for long-distance transmission; parallel interface features high speed but consumes more resources.
- Synchronous vs. Asynchronous: Synchronous communication relies on a clock line to align the timing, while asynchronous communication pre-negotiates the data rate and operates independently on each end.
- Simplex / Half-duplex / Full-duplex: correspond to unidirectional communication, two-way alternate communication, and two-way simultaneous communication respectively.
After understanding these basic concepts, we then looked at several common communication interfaces for the ESP32:
- UART: Asynchronous, serial, full-duplex, point-to-point, commonly used for debugging or GPS modules.
- I2C: A synchronous, serial, half-duplex communication protocol that supports one-to-many connections; it enables multiple devices to be connected with just two wires, and is commonly used for sensors or small displays.
- SPI: Synchronous, serial, full-duplex, supporting one-to-many topology, featuring high speed, and commonly used in LCDs and SD cards.
- CAN: Synchronous, serial, full-duplex, supporting many-to-many communication, with strong anti-interference capability, and is commonly used in automotive and industrial scenarios.
As we can see, the communication interfaces provided by the ESP32 include both simple and resource-efficient options, and high-speed and powerful ones, which can also handle complex multi-device scenarios. With a grasp of these fundamentals, we can select the appropriate communication method based on actual requirements in subsequent projects, enabling the ESP32 to interact better with the outside world.