Common Communication Interfaces in Embedded Development

In embedded systems, on-board communication interfaces refer to the communication pathways or buses used to connect various integrated circuits with other peripheral devices.

UART, I2C, RS485, etc. are commonly used. This article organizes and clarifies them.

UART Universal Asynchronous Receiver-Transmitter

Thorough Understanding of UART Communication

The UART port refers to a physical interface form (hardware).

Common Communication Interfaces in Embedded Development

UART is asynchronous, full-duplex serial bus. It is much more complex than synchronous serial ports. There are two lines, one TXD for sending and one RXD for receiving.

The serial data transmission of UART does not require a clock signal to synchronize transmission but relies on predefined configurations between the sending and receiving devices.

For the sending and receiving devices, the serial communication configurations must be set to be exactly the same.

Common Communication Interfaces in Embedded Development
  • Start bit: Indicates the beginning of data transmission, with a logic level of “0”.

  • Data bits: Possible values are 5, 6, 7, 8, 9, representing the transmission of these several bits of data. Generally, the value is 8, as one ASCII character is 8 bits.

  • Parity bit: Used by the receiver to check the received data, with the number of “1” bits being even (even parity) or odd (odd parity), to verify the correctness of data transmission. This bit can be omitted when used.

  • Stop bit: Indicates the end of a data frame. The logic level is “1”.

  • Baud rate: The rate of serial communication, represented by the number of valid bits transmitted per unit time, measured in bits per second (bps).

If simulating a UART bus with a general IO port, one input port and one output port are required. This example explains STM32 simulating serial communication through IO.

I2C Bus

Comprehensive Analysis of I2C Communication Protocol

The I2C bus is a synchronous, half-duplex two-wire serial bus. It consists of two lines: the serial clock line SCL and the serial data line SDA.

The SCL line is responsible for generating synchronous clock pulses.

The SDA line is responsible for transmitting serial data between devices.

This bus can connect multiple I2C devices to the system. Devices connected to the I2C bus can act as either master or slave devices.

Common Communication Interfaces in Embedded Development

The master device is responsible for controlling communication, initializing data transmission, sending data, and generating the required synchronous clock pulses. The slave device waits for commands from the master device and responds to the commands received.

Both the master and slave devices can act as sending or receiving devices. Regardless of whether the master device is sending or receiving, the synchronous clock signal can only be generated by the master device.

If simulating an I2C bus with a general IO port and achieving bidirectional transmission, one input/output port (SDA) is required, along with one output port (SCL).

SPI Serial Peripheral Interface

Comprehensive Analysis of SPI Communication Protocol

The SPI bus is a synchronous, full-duplex two-way four-wire serial interface bus. It consists of a system of “one master device + multiple slave devices”.

In the system, as long as only one master device is activated at any given time, multiple SPI master devices can exist. It is commonly used for communication between ADCs, EEPROMs, FLASH, real-time clocks, digital signal processors, and digital signal decoders.

Common Communication Interfaces in Embedded Development

To achieve communication, SPI has a total of four signal lines:

  • Master Out Slave In (MOSI): The signal line for transmitting data from the master device to the slave device, also known as Slave Input (SI/SDI).

  • Master In Slave Out (MISO): The signal line for transmitting data from the slave device to the master device, also known as Slave Output (SO/SDO).

  • Serial Clock (SCLK): The signal line for transmitting clock signals.

  • Slave Select (SS): The signal line used to select the slave device, active low.

The working timing mode of SPI is determined by the phase relationship between CPOL (Clock Polarity) and CPHA (Clock Phase).

CPOL indicates the initial level state of the clock signal, with CPOL = 0 indicating that the initial state is low, and CPOL = 1 indicating that the initial state is high.

CPHA indicates on which clock edge to sample data, with CPHA = 0 indicating sampling on the first clock transition edge, and CPHA = 1 indicating sampling on the second clock transition edge.

There are four working timing modes based on the different combinations of CPOL and CPHA:

  • CPOL=0, CPHA=0

  • CPOL=0, CPHA=1

  • CPOL=1, CPHA=0

  • CPOL=1, CPHA=1

Comparison of UART, SPI, and I2C

Common Communication Interfaces in Embedded Development
  • The I2C line is fewer and more powerful than UART and SPI, but technically more complicated, as I2C requires support for bidirectional IO and uses pull-up resistors, making it less resistant to interference. It is generally used for communication between chips on the same board and rarely for long-distance communication.

  • SPI implementation is simpler; UART requires a fixed baud rate, meaning the intervals between two bits of data must be equal, whereas SPI does not require this, as it is a clocked protocol.

  • I2C is slightly slower than SPI, the protocol is more complex than SPI, but it has fewer wires than standard SPI.

  • UART can transmit 5/6/7/8 bits in a frame, while I2C must be 8 bits. Both I2C and SPI start transmission from the highest bit.

  • SPI uses chip select signals to choose a slave, while I2C uses addresses to select a slave.

Common Communication Interfaces in Embedded Development

RS232 Serial Communication

Easy-to-Understand Serial Communication Knowledge: UART, TTL, RS232, USB

There are two transmission lines and one ground wire. The level is negative logic:

-3V~-15V logic “1”, +3V~+15V logic “0”.

RS-232 serial communication has a transmission distance of about 15 meters. It can achieve bidirectional transmission and full-duplex communication, with a transmission rate of 20kbps.

The following diagram shows the definitions of DB9 male and female connectors, with RXD, TXD, and GND being the most commonly used signals.

Common Communication Interfaces in Embedded Development

TTL and RS-232 Conversion

Microcontroller interfaces are generally TTL levels. If connecting to a 232 level peripheral, a TTL to RS232 conversion module is required. As shown in the figure, the MAX232 chip can be used for conversion.

Common Communication Interfaces in Embedded Development

RS422 Serial Communication

RS-422 has four signal lines: two for transmission, two for reception, and one ground wire, enabling full-duplex communication.

It has one master device and the rest are slave devices; slave devices cannot communicate with each other, thus RS-422 supports point-to-multipoint bidirectional communication.

Common Communication Interfaces in Embedded Development

RS485 Serial Communication

RS-485 uses balanced transmission and differential reception, thus having the ability to suppress common-mode interference.

It uses two-wire half-duplex transmission, with a maximum rate of 10Mb/s, and the logic level is determined by the voltage difference between the two wires, improving resistance to interference and allowing long transmission distances (from dozens of meters to thousands of meters).

+2V~+6V logic “1”, -2~-6V logic “0”.

TTL to RS-485 conversion is common, such as using MAX485; the reference circuit is shown below.

Common Communication Interfaces in Embedded Development

RE pin: Receiver output enable (active low).

DE pin: Transmitter output enable (active high). It can be controlled directly through the MCU’s IO port.

TTL

The serial port referred to in embedded systems generally refers to the UART port. It has four pins (Vcc, GND, RX, TX) and uses TTL levels.

The COM port in a PC refers to the serial communication port, commonly known as the serial port. It has nine pins and uses RS232 levels.

Common Communication Interfaces in Embedded Development

The serial port and COM port refer to a physical interface form (hardware), while TTL, RS-232, and RS-485 refer to voltage standards (electrical signals).

Common Communication Interfaces in Embedded Development

The communication schematic between the microcontroller and the PC is shown below:

Common Communication Interfaces in Embedded Development

CAN Bus

Learn CAN Communication Protocol

CAN stands for Controller Area Network, a serial communication network capable of implementing distributed real-time control. The CAN bus is complex and intelligent in function. It is mainly used for automotive communication; related articles: Detailed Explanation of CAN Bus.

The CAN bus network mainly hangs on CAN_H and CAN_L, with each node achieving serial differential transmission of signals through these two lines. To avoid signal reflection and interference, a 120-ohm termination resistor needs to be connected between CAN_H and CAN_L.

Common Communication Interfaces in Embedded Development

Each device can act as both a master and a slave. The communication distance of the CAN bus can reach 10 kilometers (at speeds lower than 5Kbps), with speeds up to 1Mbps (for distances less than 40M).

Common Communication Interfaces in Embedded Development

CAN Level Logic

The CAN bus adopts the “wired AND” rule for bus arbitration, where 1&0 equals 0, hence 0 is called dominant and 1 is recessive.

From the potential point of view, since the high potential is defined as 0 and the low potential as 1, when signals are transmitted simultaneously, the actual presentation is high potential, visually appearing as 0 covering 1, hence 0 is dominant and 1 is recessive.

Common Communication Interfaces in Embedded Development

USB Communication Serial Bus

In-Depth Understanding of USB Communication Protocol (Detailed Explanation)

The USB interface has at least four wires, two of which are data lines, and all USB data transmission is completed through these two lines. Its communication is much more complex than that of serial ports.

The two data lines use differential transmission, meaning two data lines are required to transmit one bit, thus it is half-duplex communication, where only one can send or receive at the same time.

USB specifies that if the voltage level remains unchanged, it represents logic 1; if the voltage level changes, it represents logic 0.

Common Communication Interfaces in Embedded Development

USB to TTL

Generally, USB to serial conversion uses the CH340G chip.

Common Communication Interfaces in Embedded Development

Using serial communication is simpler than USB, as serial communication does not have a protocol.

SD Card

The SD card is a type of storage card that can be used as a memory card in mobile phones.

In embedded systems, there are two modes for communication between the microcontroller and the SD card:

  • SPI Bus Communication Mode

  • SD Bus Communication Mode

Common Communication Interfaces in Embedded Development

It is worth noting that there are four data lines in the SD bus mode; in the SPI bus mode, there is only one data line (MOSI and MISO cannot read data simultaneously, nor can they write data simultaneously). Thus, in embedded systems, using the SD bus mode for communication between the microcontroller and the SD card is several times faster than using SPI bus mode.

Common Communication Interfaces in Embedded Development

1-WIRE Bus

1-Wire was introduced by Dallas (now a part of Maxim Integrated), and it is an asynchronous half-duplex serial transmission. It uses a single signal line to transmit both clock and data, and data transmission is bidirectional.

Common Communication Interfaces in Embedded Development

The data transmission rate of a single wire is generally 16.3Kbit/s, with a maximum of 142 Kbit/s, and typically, data is transmitted at rates below 100Kbit/s.

The 1-Wire line port is an open-drain or tri-state gate port, so a pull-up resistor Rp is generally required, typically selected at 5K~10KΩ.

Main applications include: identification of print cartridges or medical consumables; identification and authentication of printed circuit boards, accessories, and peripherals.

DMA Direct Memory Access

DMA is a hardware module within STM32 that operates independently of the CPU, transferring data between peripheral devices and memory, freeing the CPU and greatly improving its efficiency.

Common Communication Interfaces in Embedded Development

It can access peripherals and memory at high speeds, and the transfer is not controlled by the CPU, allowing for bidirectional communication. Therefore, using DMA can significantly increase data transfer speeds, which is a highlight of the ARM architecture—DMA bus control.

DMA is akin to a high-speed highway, with dedicated and high-speed characteristics. If DMA is not used, the goal can still be achieved, but it will take a longer time.

Ethernet

Ethernet is currently the most widely used local area network technology. As you know, Ethernet interfaces can be divided into protocol layers and physical layers.

The protocol layer is implemented by a single module called the MAC (Media Access Control) controller.

The physical layer consists of two parts: PHY (Physical Layer) and transceiver.

Currently, many southbridge chips on motherboards include Ethernet MAC control functionality but do not provide physical layer interfaces. Thus, PHY chips need to be externally connected to provide access to Ethernet.

Common Communication Interfaces in Embedded Development

The role of the network transformer is:

  • To couple differential signals, enhancing anti-interference capability.

  • To isolate different voltage levels from different devices at the network line, isolating DC signals.

The reference circuit for the Ethernet interface is shown in the figure below.

Common Communication Interfaces in Embedded Development

The source of this article is from the internet, and the copyright belongs to the original author. If there is any infringement, please contact and delete.

END

Kepri Enterprise IT Academy

Nanjing Kepri Information Technology Co., Ltd. has long focused on promoting the digital/information technology construction and development of governments and enterprises, providing customers with specialized services including IT technology and management training, IT operation and maintenance services, information security services, business intelligence services, OA application services, and human resources outsourcing. After years of development, Kepri has formed a business service model centered on the Nanjing company, with branches in Hangzhou and Shanghai, covering East China and radiating nationwide, serving over 5000 customers across various industries such as telecommunications, finance, electric power, petrochemicals, tobacco, taxation, public security, social security, and finance, gaining widespread customer recognition!

Kepri Enterprise IT Academy was founded in 2002 and is affiliated with Nanjing Kepri Information Technology Co., Ltd. It is dedicated to providing professional digital/information talent training service solutions for government and enterprise clients, helping clients build and cultivate a sustainable professional talent pipeline. The company has a team of over a hundred expert instructors composed of industry veterans and certified instructors from manufacturers, offering more than a hundred IT technology and management courses across different professional directions, focusing on globally recognized IT manufacturers and mainstream domestic information innovation ecosystem manufacturers’ products and technologies.

Based on the increasingly stratified and diversified digital/information business needs of customers, Kepri Enterprise IT Academy designs reasonable and effective specialized training implementation plans based on professional communication, consulting, and assessment, emphasizing the relevance, practicality, and efficiency of courses, relying on the IT expert instructor team to provide high-quality and efficient training services, helping customers effectively improve employees’ professional technical capabilities and work efficiency, and reduce enterprise operation costs.

Corporate Mission:

Create value for employees, create value for customers, create value for society, and strive to promote the progress of society!

Corporate Vision:

To become China’s leading provider of enterprise-level digital talent training solutions!

Service Hotline: 025-87787966

Nanjing Campus: No. 300 Zhongshan East Road, Nanjing

Changfa Center Building A, 23rd Floor

Hangzhou Campus: Dongfang Mao Commercial Center, Xiacheng District, Hangzhou

6th Floor, Building 2

Shanghai Campus: No. 33 Leshan Road, Xuhui District, Shanghai

4th Floor, Building 2

Academy Website: www.china-esp.com

Common Communication Interfaces in Embedded Development
Common Communication Interfaces in Embedded Development

Scan to follow

Leave a Comment

×