1. Physical Interface
A physical interface is a hardware specification for the physical connection between devices, including connector type (such as USB, HDMI), pin arrangement, mechanical structure, etc. Generally, the term "physical interface" refers to the connector type.
It ensures that devices are correctly connected at the physical layer, providing a physical channel for signal transmission.
For example, USB Type-A, RJ45 network port, and HDMI interface.
2. Level Standard
Level standards specify the range of signal voltages to distinguish logic states (such as 0 and 1) and ensure electrical compatibility between the transmitting and receiving ends.
Function: Defines the electrical characteristics of signals to avoid bit errors or hardware damage.
Such as TTL (0V/5V), RS-232 (±3~15V), LVDS (Low Voltage Differential Signaling).
3. Communication Protocol
Communication protocols are the logical rules governing data transmission, including data format, timing, error checking, and addressing. They ensure that data is packaged, transmitted, and parsed according to agreed-upon rules. Examples include UART (Asynchronous Serial Protocol), SPI (Synchronous Serial Protocol), and TCP/IP (Network Protocol).
4. Bus
A bus is a shared communication channel that integrates physical interfaces, voltage levels, and protocols, allowing multiple devices to communicate over the same line. Its primary function is to provide a complete communication architecture and coordinate data exchange among multiple devices.
Physical interfaces and voltage levels belong to the underlying hardware layer (physical layer), which defines how connections are made and how signals are represented.
Communication protocols belong to the logic layer and application layer, and define the rules for data transmission.
Bus is a comprehensive concept that integrates the first three elements to form a complete communication system.
The entire collaboration process is as follows:
Devices connect via physical interfaces and transmit signals according to electrical level standards. Communication protocols ensure that data is correctly encapsulated, addressed, and verified. The bus manages shared channels and coordinates communication among multiple devices (e.g., arbitration mechanisms, collision avoidance). The implementation of the bus relies on physical interfaces (connection methods), electrical level standards (signal electrical characteristics), and communication protocols (data rules).
The same physical interface may support different voltage levels and protocols (e.g., RS-232 and RS-485 share the DB9 interface, but their voltage levels and protocols are different).
The same protocol can be adapted to different physical interfaces and voltage levels (e.g., Modbus can run on RS-485 or TCP/IP).
The numerous communication protocol concepts can actually be divided into four main categories: physical interface, voltage level standard, communication protocol, and bus.
1. Physical Interface
A physical interface is a hardware specification for the physical connection between devices, including connector type (such as USB, HDMI), pin arrangement, mechanical structure, etc. Generally, the term "physical interface" refers to the connector type.
It ensures that devices are correctly connected at the physical layer, providing a physical channel for signal transmission.
For example, USB Type-A, RJ45 network port, and HDMI interface.
2. Level Standard
Level standards specify the range of signal voltages to distinguish logic states (such as 0 and 1) and ensure electrical compatibility between the transmitting and receiving ends.
Function: Defines the electrical characteristics of signals to avoid bit errors or hardware damage.
Such as TTL (0V/5V), RS-232 (±3~15V), LVDS (Low Voltage Differential Signaling).
3. Communication Protocol
Communication protocols are the logical rules governing data transmission, including data format, timing, error checking, and addressing. They ensure that data is packaged, transmitted, and parsed according to agreed-upon rules. Examples include UART (Asynchronous Serial Protocol), SPI (Synchronous Serial Protocol), and TCP/IP (Network Protocol).
4. Bus
A bus is a shared communication channel that integrates physical interfaces, voltage levels, and protocols, allowing multiple devices to communicate over the same line. Its primary function is to provide a complete communication architecture and coordinate data exchange among multiple devices.
1. Overview of Embedded System Communication Interfaces
1.1. Role of onboard communication interface
In embedded systems, on-board communication interfaces play a crucial role, serving as key pathways or buses for integrated circuits to interact with other peripheral devices. These interfaces are responsible for transmitting data and control signals within the system, ensuring that all components can work together effectively.
1.2. Commonly Used Communication Interfaces
Commonly used onboard communication interfaces include I2C, SPI, UART, and 1-Wire. Next, we will discuss the working principles and application scenarios of these interfaces in detail.
2. I2C bus
2.1. Bus Characteristics and Structure
The I2C bus is a synchronous, bidirectional, half-duplex, two-wire serial interface bus developed and marketed by Philips Semiconductor in the early 1980s. Its initial design purpose was to provide a simple method for connecting microprocessor/microcontroller systems to television peripheral chips. The bus consists of two lines: a serial clock line (SCL) and a serial data line (SDA). The SCL line generates the synchronous clock pulse, while the SDA line is used to transmit serial data between devices.
The I2C bus is shared, allowing multiple I2C devices to connect to the same system. These devices can act as either masters to control communication or slaves to respond to commands from the master. Both masters and slaves can be senders or receivers, but the generation of the synchronization clock signal is the sole responsibility of the master. Furthermore, the I2C bus supports the coexistence of multiple masters.
2.2. Data Transmission Mechanism
Regarding the specific definition of the start signal: while the SCL line is held high, the master pulls the SDA line low, marking the start of data transmission. The transmission of the slave address and the setting of the read/write control bits follow certain rules: the first byte sent by the master contains the slave's address and read/write control bits.
Data transmission: After the slave address is sent, some specific instructions may follow, depending on the slave's implementation. Data transmission then begins and can be sent by either the master or slave. Each transmission consists of 8 bits of data, and the number of bytes is unlimited.
Stop condition: The stop condition is that while the SDA line is kept low, the host pulls the SCL line high and maintains this high level, and then pulls the SDA line high again, thus indicating the end of data transmission.
3. SPI bus
3.1. Bus Structure and Usage
The SPI bus, first proposed by Motorola, is a synchronous, bidirectional, full-duplex, 4-wire serial interface bus. It consists of one master device and multiple slave devices. It is important to note that only one master device can be active at any given time, meaning that multiple SPI master devices can exist in the system. The SPI bus is widely used for communication between devices such as EEPROMs, FLASH memory, real-time clocks, AD converters, digital signal processors, and digital signal decoders.
The clock signal for the slave device is provided by the master device via SCLK, and MOSI and MISO use this pulse for data transmission.
3.2. Communication Timing and Mode
The SPI bus is equipped with four signal lines, including SCK (clock signal), MOSI (master output, slave input), MISO (master input, slave output) and CS (chip select signal).
The master device selects the slave device by manipulating the CS pin. At any given time, only one SPI master device's CS pin is active, and the connected slave device can communicate with the master device at that time. This **"one master, multiple slaves" architecture** greatly improves the system's scalability and flexibility.
4. UART communication protocol
UART, or Universal Asynchronous Receiver/Transmitter, is an asynchronous serial communication protocol that transmits data bit by bit. In application development, it is often used as a data bus because it supports efficient data transmission. The simple and efficient mechanism of UART in asynchronous data transmission has led to its widespread application in many embedded systems and microcontrollers.
5.1 - Wire Interface and Parallel Interface
5.1.1 - Characteristics of Wire Interface
The 1-Wire interface, also known as the Dallas 1-Wire protocol, is an asynchronous half-duplex communication protocol meticulously developed by Maxim Dallas Semiconductor. This interface can transmit power simultaneously on the signal line. This characteristic allows the 1-Wire interface to connect not only a master device but also one or more slave devices.
5.2. Parallel Interface Structure and Usage
Parallel interfaces are commonly used for communication between a system and peripheral devices. These peripheral devices are mapped to the system's main controller via memory. As long as the embedded system's main processor/controller is equipped with a parallel bus, devices that support the parallel bus can be directly connected to it. Peripheral devices are mapped to the main processor via memory, thus allowing them to access specific address ranges.
There are four interfaces, each with its own suitable application scenarios, varying in hardware port usage, software control requirements, and communication efficiency. The first three, in particular, are commonly used protocols, generally supporting hardware interfaces, and manufacturers typically provide HAL libraries, thus lowering the requirements for software developers. This can lead to fluent application code but a slight lack of understanding of the underlying principles, leaving developers at a loss when communication anomalies or special requirements arise. Examples include using GPIO to simulate UART and using SPI to implement AT functionality.