2531 views|2 replies

119

Posts

0

Resources
The OP
 

UART, I2C, SPI, TTL, RS232, RS422, RS485, CAN, USB, SD card, 1-WIRE, Ethernet [Copy link]

In microcontroller development, UART, I2C, RS485, etc. are commonly used, and the understanding of them may be ambiguous. This article sorts them out.

UART Universal Asynchronous Receiver/Transmitter

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

UART is an asynchronous, full-duplex serial bus. It is much more complex than a synchronous serial port. It has two wires, one TXD for sending and one RXD for receiving.

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

The serial communication configurations of both the sending and receiving devices should be set to be exactly the same.

Start bit: indicates the beginning of data transmission, the level logic is "0".

Data bit: Possible values are 5, 6, 7, 8, and 9, indicating the transmission of these bits of data. The general value is 8, because an ASCII character has 8 bits.

Parity bit: used by the receiver to check the received data, checking whether the number of "1" bits is even (even parity) or odd (odd parity), so as to verify the correctness of data transmission. This bit is not required when using it.

Stop bit: indicates the end of a frame of data. The level logic is "1".

If you use a general-purpose IO port to simulate a UART bus, you will need one input port and one output port.

I2C Bus

The I2C bus is a synchronous, half-duplex, bidirectional, two-wire serial bus. It consists of two buses: 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. The device connected to the I2C bus can act as either a master device or a slave device.

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

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

If you use a general-purpose IO port to simulate the I2C bus and implement bidirectional transmission, you will need an input/output port (SDA) and an output port (SCL).

SPI serial peripheral interface

The SPI bus is a synchronous, full-duplex, bidirectional, 4-wire serial interface bus. It is a system consisting of a "single master device + multiple slave devices".

In the system, there can be multiple SPI master devices as long as only one master device is active at any time. It is often used to achieve communication between AD converters, EEPROM, FLASH, real-time clocks, digital signal processors and digital signal decoders.

In order to achieve communication, SPI has 4 signal lines, namely:

Master Out Slave In (MOSI) : The signal line that transmits data from the master device to the slave device, also known as slave input ( Slave Input/Slave Data In, SI/SDI).

Master In Slave Out (MISO) : The signal line that transmits data from the slave device to the master device, also known as slave output ( Slave Output/Slave Data Out, SO/SDO).

Serial Clock ( SCLK) : A signal line that transmits clock signals.

Slave Select ( SS) : Signal line used to select slave devices, low level is valid.

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 of the clock signal. CPOL is 0, which means the initial state of the clock signal is low level, and 1, which means the initial level of the clock signal is high level. CPHA indicates the clock edge at which data is sampled. CPHA is 0, which means the data is sampled at the first clock change edge, and CPHA is 1, which means the data is sampled at the second clock change edge.

Comparison of UART, SPI and I2C

I2C has fewer lines and is more powerful than UART and SPI, but it is also more technically complex because I2C requires the support of bidirectional IO and uses pull-up resistors, which has weak anti-interference ability. It is generally used for communication between chips on the same board and is rarely used for long-distance communication.

SPI is simpler to implement. UART requires a fixed baud rate, which means that the interval between two bits of data must be equal, but SPI does not matter because it is a clocked protocol.

I2C is a bit slower than SPI and has a more complex protocol, but it also has fewer wires than standard SPI.

UART can transmit 5/6/7/8 bits per frame, while I2C must transmit 8 bits. Both I2C and SPI start transmitting from the highest bit.

SPI uses chip select signal to select slave, I2C uses address to select slave.

RS232 serial communication

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

-3V~-15V logic "1", +3V~+15V logic "0".

RS-232 serial communication transmission distance is about 15 meters. It can achieve two-way transmission, full-duplex communication, and the transmission rate is as low as 20kbps.

The figure below shows the definition of DB9 male and female connectors. The three most commonly used signals are RXD, TXD, and GND.

TTL and RS-232 conversion

The interface of the microcontroller is usually TTL level. If you want to connect a 232 level peripheral, you need to add a TTL to RS232 module. As shown in the figure below, you can use the MAX232 chip for conversion.

RS422 serial communication

RS-422 has four signal lines: two for sending, two for receiving and one for grounding, which is full-duplex communication.

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

RS485 serial communication

RS-485 uses balanced transmission and differential reception, so it has the ability to suppress common-mode interference.

It adopts two-wire half-duplex transmission with a maximum rate of 10Mb/s. The level logic is determined by the level difference between the two lines, which improves the anti-interference ability and has a long transmission distance (tens of meters to thousands of meters).

+2V~+6V logic "1", -2~-6V logic "0".

It is very common to convert TTL to RS-485, such as MAX485. The reference circuit is as follows

RE pin: Receiver output enable (active low).

DE pin: Transmitter output enable (high level is valid). Can be directly controlled by the MCU's IO port.

TTL

The serial port mentioned in embedded system usually refers to UART port, which has 4 pins (Vcc, GND, RX, TX) and uses TTL level.

The COM port in the PC is the serial communication port, also known as the serial port. It has 9 pins and uses RS232 level.

Serial port and COM port refer to the physical interface form (hardware), while TTL, RS-232, and RS-485 refer to the level standard (electrical signal).

The schematic diagram of communication between MCU and PC is as follows:

CAN bus

CAN is the abbreviation of Controller Area Network, which is a serial communication network that can realize distributed real-time control. The functions of CAN bus are complex and intelligent. It is mainly used for automobile communication.

The CAN bus network is mainly connected to CAN_H and CAN_L. Each node realizes serial differential transmission of signals through these two lines. In order to avoid signal reflection and interference, a 120-ohm terminal resistor is also required between CAN_H and CAN_L.

Each device can be a master or a slave. The communication distance of the CAN bus can reach 10 kilometers (rate less than 5Kbps) and the speed can reach 1Mbps (communication distance less than 40M).

CAN level logic

The CAN bus uses the "wire and" rule for bus punching, 1&0 is 0, so 0 is called dominant and 1 is recessive.

From the perspective of electric potential, because the high potential is stipulated as 0 and the low potential is 1, when the signal is sent at the same time, it actually presents a high potential. From the phenomenon, it looks like 0 covers 1, so 0 is called dominant and 1 is recessive.

USB communication serial bus

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

The two data lines use differential transmission, that is, two data lines are needed to transmit one bit, so it is half-duplex communication, and only one can be sent or received at the same time.

USB stipulates that if the voltage level does not change, it represents a logical 1; if the voltage level changes, it represents a logical 0.

USB to TTL

Generally, USB to serial port converters use CH340G chip.

Serial communication is simpler than USB because there is no protocol for serial communication.

SD Card

SD card is a memory card that can be used in mobile phones as a memory card.

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

SPI bus communication mode

SD bus communication mode

It is worth noting that there are 4 data lines in SD bus mode; there is only one data line in SPI bus mode (MOSI and MISO cannot read data or write data at the same time); thus, in embedded systems, the SD bus mode is several times faster than the SPI bus mode when the microcontroller communicates with the SD card.

1-WIRE bus

1-Wire was introduced by Dallas, USA, and is an asynchronous half-duplex serial transmission. It uses a single signal line to transmit both clock and data, and the data transmission is bidirectional.

The data transmission rate of a single bus is generally 16.3 Kbit/s, and can reach a maximum of 142 Kbit/s. Normally, data is transmitted at a rate of less than 100 Kbit/s.

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

Main applications: 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 in STM32. It is independent of the CPU and performs data transfer between peripheral devices and memory, freeing up the CPU and greatly improving its efficiency.

It can access peripherals and memory at high speed, the transmission is not controlled by the CPU, and it is a two-way communication. Therefore, using DMA can greatly increase the data transmission speed, which is also a highlight of the ARM architecture - DMA bus control.

DMA is like a highway, dedicated and high-speed. If you don't use DMA, you can still achieve your goal, but it will take longer.

Ethernet

Ethernet is the most commonly used LAN technology currently.

As we all know, the Ethernet interface can be divided into the protocol layer and the physical layer.

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

The physical layer consists of two parts, namely PHY (Physical Layer) and transmitter.

Currently, the south bridge chips of many motherboards already include Ethernet MAC control functions, but do not provide physical layer interfaces. Therefore, an external PHY chip is required to provide an Ethernet access channel.

The functions of the network transformer are:

Coupled differential signal, stronger anti-interference ability

The transformer isolates the different voltage levels of different devices at the network cable end and isolates the DC signal

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

丨The article is organized to spread relevant technologies, the copyright belongs to the original author丨

丨If there is any infringement, please contact us to delete丨

This post is from MCU

Latest reply

In addition to I2C, there is now I3C.   Details Published on 2021-7-19 15:59
Personal signature

嵌入式、汇编语言等免费视频<

 

8

Posts

0

Resources
2
 

Very detailed write-up, thanks for sharing

This post is from MCU
 
 

1w

Posts

25

Resources
3
 

In addition to I2C, there is now I3C.

This post is from MCU
 
 
 

Just looking around
Find a datasheet?

EEWorld Datasheet Technical Support

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号
快速回复 返回顶部 Return list