Understanding UART, TTL, RS232, RS422, RS485, CAN, and USB

UART, I2C, RS485… Although these communication methods are commonly used, their explanations can be ambiguous. I felt it necessary to organize them to consolidate and distinguish the concepts. The article is a bit lengthy, so I suggest saving it for future reference when needed.
UART Universal Asynchronous Receiver-Transmitter
The UART port refers to a physical interface form (hardware).
Understanding UART, TTL, RS232, RS422, RS485, CAN, and USB
UART is asynchronous, full-duplex serial bus. It is much more complex than synchronous serial ports. There are two lines, one TXD for transmission and one RXD for reception.
UART’s serial data transmission does not require a clock signal for synchronization but relies on a predefined configuration between the sending and receiving devices.
For both the sending and receiving devices, their serial communication configurations should be set to be identical.
Understanding UART, TTL, RS232, RS422, RS485, CAN, and USB
Start Bit: Indicates the beginning of data transmission, with a logic level of “0”.
Data Bits: Possible values are 5, 6, 7, 8, or 9, indicating the transmission of these bits of data. Generally, the value is set to 8 because an ASCII character is 8 bits.
Parity Bit: Used by the receiver to check the received data; the number of bits with a parity of “1” is even (even parity) or odd (odd parity), thus verifying the correctness of data transmission. This bit is optional.
Stop Bit: Indicates the end of a frame of data. The logic level is “1”.
If using a general IO port to simulate a UART bus, one input port and one output port are required.
I2C Bus
The I2C bus is a synchronous, half-duplex bi-directional two-wire serial bus. It consists of two lines: the serial clock line SCL and the serial data line SDA.
SCL line – responsible for generating synchronous clock pulses.
SDA line – 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.
Understanding UART, TTL, RS232, RS422, RS485, CAN, and USB
The master device controls communication by initializing data transmission, sending data, and generating the required synchronous clock pulses. The slave device waits for commands from the master and responds to receive commands.
Both 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 using a general IO port to simulate the I2C bus and achieve bi-directional transmission, one input-output port (SDA) and one output port (SCL) are needed.
SPI Serial Peripheral Interface
The SPI bus is a synchronous, full-duplex bi-directional 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 active at any time, multiple SPI master devices can exist. It is commonly used for communication between AD converters, EEPROM, FLASH, real-time clocks, digital signal processors, and digital signal decoders.
To achieve communication, SPI has a total of four signal lines:

Understanding UART, TTL, RS232, RS422, RS485, CAN, and USB

(1) Master Out Slave In (MOSI): The signal line for transmitting data from the master device to the slave device, also known as slave input (Slave Input/Slave Data In, SI/SDI).
(2) Master In Slave Out (MISO): The signal line for transmitting data from the slave device to the master device, also known as slave output (Slave Output/Slave Data Out, SO/SDO).
(3) Serial Clock (SCLK): The signal line for transmitting clock signals.
(4) 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 state of the clock signal; CPOL = 0 means the initial state is low, while CPOL = 1 means the initial state is high. CPHA indicates which clock edge samples the data; CPHA = 0 means sampling occurs on the first clock transition, while CPHA = 1 means sampling occurs on the second clock transition.
Understanding UART, TTL, RS232, RS422, RS485, CAN, and USB
Comparison of UART, SPI, and I2C
① The I2C line is fewer and more powerful than UART and SPI, but technically more complicated because I2C requires support for bi-directional IO and uses pull-up resistors, making it more susceptible to interference. It is generally used for communication between chips on the same board and less for long-distance communication.
② SPI is simpler to implement, while UART requires a fixed baud rate, meaning the interval between two bits of data must be equal, while SPI does not have this requirement as it is a clock-based protocol.
③ I2C is slightly slower than SPI; its protocol is more complicated than SPI, but it requires fewer wires than standard SPI.
④ A UART frame can transmit 5/6/7/8 bits, while I2C must be 8 bits. Both I2C and SPI transmit starting from the highest bit.
⑤ SPI uses chip select signals to select slaves, while I2C uses addresses to select slaves.
Understanding UART, TTL, RS232, RS422, RS485, CAN, and USB
RS232 Serial Communication
There are two transmission lines and one ground line. The logic levels are negative:
-3V~-15V logic “1”, +3V~+15V logic “0”.
RS-232 serial communication transmission distance is about 15 meters. It can achieve bi-directional transmission and full-duplex communication with a transmission rate of up to 20kbps.
The following diagram shows the definition of DB9 male and female connectors, with the most commonly used signals being RXD, TXD, and GND.
Understanding UART, TTL, RS232, RS422, RS485, CAN, and USB
TTL and RS-232 Conversion
Microcontroller interfaces generally use TTL levels. If connecting to RS232 level peripherals, a TTL to RS232 module is required. As shown in the figure, the MAX232 chip can be used for conversion.
Understanding UART, TTL, RS232, RS422, RS485, CAN, and USB
RS422 Serial Communication
RS-422 has four signal lines: two for transmission, two for reception, and one ground line. It supports full-duplex communication.
It has one master device, and the rest are slave devices. Slave devices cannot communicate with each other, so RS-422 supports point-to-multipoint bi-directional communication.
Understanding UART, TTL, RS232, RS422, RS485, CAN, and USB
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. The logic levels are determined by the voltage difference between the two wires, improving anti-interference capability and allowing long-distance transmission (from several dozen meters to over a thousand meters).
+2V~+6V logic “1”, -2~-6V logic “0”.
TTL to RS-485 conversion is common, such as using MAX485; the reference circuit is as follows:
Understanding UART, TTL, RS232, RS422, RS485, CAN, and USB
RE pin: Receiver output enable (active low).
DE pin: Transmitter output enable (active high). It can be controlled directly via the MCU’s IO port.
TTL
The serial port referred to in embedded systems generally means the UART port. It has 4 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 9 pins and uses RS232 levels.
Understanding UART, TTL, RS232, RS422, RS485, CAN, and USB
The serial port and COM port refer to a physical interface form (hardware). TTL, RS-232, and RS-485 refer to voltage standards (electrical signals).
Understanding UART, TTL, RS232, RS422, RS485, CAN, and USB
The communication diagram between the microcontroller and PC is as follows:
Understanding UART, TTL, RS232, RS422, RS485, CAN, and USB
CAN Bus
CAN stands for Controller Area Network, a serial communication network capable of distributed real-time control. The CAN bus is complex and intelligent, primarily used for automotive communication.
The CAN bus network mainly hangs on CAN_H and CAN_L, with each node transmitting signals differentially through these two lines. To avoid signal reflection and interference, a 120-ohm termination resistor is required between CAN_H and CAN_L.
Understanding UART, TTL, RS232, RS422, RS485, CAN, and USB
Each device can act as either a master or a slave. The communication distance of the CAN bus can reach up to 10 kilometers (at a rate lower than 5Kbps), and speeds can reach up to 1Mbps (communication distance less than 40M).
Understanding UART, TTL, RS232, RS422, RS485, CAN, and USB
CAN Logic Levels
CAN bus uses the “AND” rule for bus arbitration, where 1 & 0 equals 0, hence 0 is called dominant and 1 is recessive.
From the potential perspective, since the high potential is defined as 0 and the low potential as 1, when signals are sent simultaneously, the actual signal appears as high potential, making it seem like 0 covers 1, hence 0 is dominant and 1 is recessive.
Understanding UART, TTL, RS232, RS422, RS485, CAN, and USB
USB Serial Bus Communication
The USB interface typically has at least four wires, two of which are data lines, and all USB data transmissions are completed through these two lines. Its communication is much more complex than that of serial ports.
The two data lines use differential transmission, meaning that two data lines must work together to transmit one bit, thus it is half-duplex communication, allowing either sending or receiving 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.
Understanding UART, TTL, RS232, RS422, RS485, CAN, and USB
USB to TTL
Generally, USB to serial conversion uses the CH340G chip.
Understanding UART, TTL, RS232, RS422, RS485, CAN, and USB
Using serial communication is simpler than USB because 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 for mobile phones.
In embedded systems, there are two modes for communication between microcontrollers and SD cards:
1. SPI bus communication mode;
2. SD bus communication mode.
Understanding UART, TTL, RS232, RS422, RS485, CAN, and USB
It is worth noting that the SD bus mode has four data lines, while the SPI bus mode has only one data line (MOSI and MISO cannot read data simultaneously nor write data simultaneously). Thus, when communicating with the SD card in embedded systems, the SD bus mode is faster than the SPI bus mode by several times.
Understanding UART, TTL, RS232, RS422, RS485, CAN, and USB
1-WIRE Bus
1-Wire was introduced by the American company Dallas and is an asynchronous half-duplex serial transmission method. It uses a single signal line to transmit both clock and data, and data transmission is bi-directional.
Understanding UART, TTL, RS232, RS422, RS485, CAN, and USB
The data transmission rate of the single wire is generally 16.3Kbit/s, with a maximum rate of 142 Kbit/s, and typically operates at rates below 100Kbit/s.
The 1-Wire line port is typically an open-drain or tri-state gate port, so a pull-up resistor Rp is usually required, typically chosen as 5K~10KΩ.
Main applications include: identification of printing cartridges or medical consumables; identification and authentication of printed circuit boards, accessories, and peripherals.
DMA Direct Memory Access
DMA is a hardware module within the STM32 that operates independently of the CPU to transfer data between peripheral devices and memory, freeing up the CPU and greatly improving its efficiency.
Understanding UART, TTL, RS232, RS422, RS485, CAN, and USB
It allows for high-speed access to peripherals and memory, with data transfer not controlled by the CPU, and it supports bi-directional communication. Therefore, using DMA can significantly enhance data transfer speeds, which is a highlight of the ARM architecture – DMA bus control.
DMA corresponds to a high-speed highway, with dedicated and high-speed characteristics. If DMA is not used, the objective can still be achieved, but it will take longer to reach that goal.
Ethernet
Ethernet is currently the most widely used LAN technology.
As we know, the Ethernet interface can be divided into protocol layer and physical layer.
The protocol layer is implemented by a single module called the MAC (Media Access Control) controller.
The physical layer consists of two parts: the PHY (Physical Layer) and the transceiver.
Currently, many motherboard southbridge chips already include Ethernet MAC control functions, but they do not provide physical layer interfaces. Therefore, an external PHY chip is needed to provide access to Ethernet.
Understanding UART, TTL, RS232, RS422, RS485, CAN, and USB
The role of the network transformer is:
To couple differential signals and enhance anti-interference capability;
To isolate different levels of different devices at the network line, isolating DC signals.
Reference circuit for Ethernet interface:
Understanding UART, TTL, RS232, RS422, RS485, CAN, and USB
—END—
Source: Internet, copyright belongs to the original author, infringement will be deleted

Previous Issues

Design and Installation of Distribution Cabinets and Panels

2021-06-08

Understanding UART, TTL, RS232, RS422, RS485, CAN, and USB

Fun Summary of PID Algorithm, Ensuring You Understand at a Glance!

2021-06-07

Understanding UART, TTL, RS232, RS422, RS485, CAN, and USB

[Academic Frontier] Tsinghua University Zhang Ning: Thoughts on the Development Direction of China’s Power System Technology Aimed at Carbon Neutrality!

2021-06-04

Understanding UART, TTL, RS232, RS422, RS485, CAN, and USB

Complete Supply Chain of the Energy Storage Industry!

2021-06-03

Understanding UART, TTL, RS232, RS422, RS485, CAN, and USB

Understanding the Differences Between DTU, FTU, TTU, and RTU in One Article!

2021-06-02

Understanding UART, TTL, RS232, RS422, RS485, CAN, and USB

Do You Understand These Basic Concepts of Power System Operation?

2021-06-01

Understanding UART, TTL, RS232, RS422, RS485, CAN, and USB

Understanding UART, TTL, RS232, RS422, RS485, CAN, and USB
-Scan to Follow-
Welcome to add the official WeChat of Electrical Applications, various professional groups are available!

Understanding UART, TTL, RS232, RS422, RS485, CAN, and USB

Leave a Comment