Serial port, COM, UART, TTL, USB, RS-232, RS-485, I2C, SPI, CAN, 1-wire
Serial port
Overview of Serial Ports
The serial interface is abbreviated as a serial port, also known as a serial communication interface, generally also known as a COM port. This is a general term, and interfaces that use serial communication are called serial ports. A serial port is a hardware interface.
Male and female heads
There is a distinction between male and female heads, which can be remembered by everyone. The one with a hole on the left is the female head, and the other is the male head.

Male and female
Serial and parallel
Serial: A communication method that transmits one bit of data at a time on a computer bus or other data channel, and continues the above single process.
Parallel: Communication is performed on a serial port by transmitting several bits of data at a time, so parallel is faster than serial.

serial and parallel
UART
UART is the abbreviation of Universal Asynchronous Receiver/Transmitter, which means universal asynchronous receiver/transmitter. UART includes TTL level serial port and RS-232 level serial port. Both devices using UART communication need to comply with the UART protocol.
TTL level
Overview of TTL
TTL is the abbreviation of Transistor-Transistor Logic, which is a level logic, transistor-transistor logic.
Standard TTL level logic
Logic 1 represents a high level and is connected to the power supply VCC, and logic 0 represents a low level and is connected to the power supply ground.
● Logic 1, high level, VCC (3.3V/5V)
● Logic 0, low level, GND (0V)
TTL has a voltage range, which is divided into output high and low levels and input high and low levels. The output high level is represented by V O H V_{OH}VOH, and the output low level is represented by V O L V_{OL}VOL; the input high level The level is represented by V I H V_{IH}VIH, and the input low level is represented by V I L V_{IL}VIL.
For TTL level devices, when the input voltage is higher than 2V, it will be recognized as logic 1, and when the input low level is lower than 1.2V, it will be recognized as 0. This is why the output is high level. 2.4V, higher than 2V; output low level 0.8V, lower than 1.2V. The following are standard TTL levels. There are many types of TTL, and the voltages are different.
● V O H > 2.4 V, V O L < 0.8 V V_{OH}>2.4V, V_{OL}<0.8VVOH>2.4V, VOL<0.8V
● V I H > 2.0 V, V I L < 1.2 V V_{IH}>2.0V, V_{IL}<1.2VVIH>2.0V, VIL<1.2V
USB to TTL
Friends who have played with 51 microcontrollers have used the CH340G module to download HEX files. The function of this module is to convert USB to TTL levels. Generally, the levels of microcontrollers are TTL levels. The internal chip of the module is CH340T. ST official recommendation.

USB to TTL module
Circuit schematic diagram of USB to TTL level using CH340T chip.

Connect with microcontroller
Communication between TTL level devices only requires three signal lines: TXD, RXD and GND. The connection with the microcontroller is very simple. For a 3.3V microcontroller, connect it to 3.3V, and for a 5V microcontroller, connect it to 5V. If the microcontroller has a separate power supply, 3.3 Neither V nor 5V are connected.

Connection between USB to TTL module and microcontroller
USB
USB overview
USB is the abbreviation of Universal Serial Bus. It is an external bus standard used to standardize the connection and communication between computers and external devices. It is an interface technology applied in the PC field. It is characterized by fast transmission speed and support for hot plugging. Unplug and connect multiple devices.
We can see USB in many places, such as mice, keyboards, and mobile phone chargers. Now almost all electronic charging equipment has USB interfaces. The following are the physical interfaces of each USB.

USB interface classification
USB speed
● 1MB/s=8Mbps (1 Byte equals 8bit)
● USB1.0 Low Speed transmission rate is 1.5Mbps;
● USB1.1 Full Speed transmission rate is 12Mbps;
● USB2.0 High Speed transmission rate is 480Mbps;
● USB3.0 SuperSpeed transmission rate is 5Gbps;
● USB3.1 Gen2 SuperSpeed+ transfer rate is 10Gbps;
USB interface definition
The most common Type-A USB interface is defined as follows.
| Pin# | Name | Color |
| 1 | VBUS/+5V | red |
| 2 | D-/Data-/DM | White |
| 3 | D+/Data+/DP | green |
| 4 | GND | black |

Type-A interface
RS-232
Overview of RS-232
The RS-232 interface complies with the interface standard for serial data communication established by the Electronic Industries Alliance (EIA). The full name of the original number is EIA-RS-232 (referred to as 232, RS232). It is widely used for computer serial interface peripheral connections, connecting cables and mechanical, electrical characteristics, signal functions and transmission processes.
RS-232 level logic
RS-232 is different from the level logic of TTL. It is negative logic. Negative 12V represents high-level logic 1, and positive 12V represents low-level logic 0. The voltage also has a standard range.
● High level, logic 1, -15V to -3V
● Low level, logic 0, +3V to +15
In addition to TTL, RS232, there is also a CMOS level standard.
● V O H > 0.9 ∗ V C C V_{OH}>0.9*VCC
● VOH>0.9*VCC, V O L < 0.1 ∗ V C C V_{OL}<0.1*VCCVOL<0.1*VCC
DB9 interface definition
The picture below is the definition of DB9 male and female connectors. Generally, the three most commonly used signals are RXD, TXD, and GND.

DB9 male and female interface signal definitions
DB-25's RS232 is also used in industrial situations, and the DB9 and DB25 interfaces can be converted.

USB to RS-232
To convert USB to 232, you can first convert USB to TTL, and then convert TTL to RS232. Of course, there are also many USB to RS232 cables on the market. The cable has an integrated conversion circuit inside. The two chips used to convert USB to RS232 on Taobao are FT232. and SP213.

TTL and RS-232 mutual conversion
The MCU interface is generally TTL level. If you need to connect 232 level peripherals, you need to add a TTL to RS232 module. The conversion direction is bidirectional.
The most commonly used chips for converting TTL and RS232 levels are MAX232 and SP3232.

RS-485
Overview of RS-485
RS-485 and RS-232 are both serial communication standards. The current standard name is TIA/EIA-485-A, which is commonly called the RS-485 standard. RS-485 makes up for the short communication distance and speed of RS-232. Low disadvantages.
RS-485 is different from RS-232 single-ended transmission. It is differential transmission and uses a pair of twisted pairs, one of which is defined as A and the other as B.
RS-485 level logic
RS-485 is differential transmission. Generally, the transceiver is composed of a transmitter and a transceiver. The figure below is a typical functional block diagram of a transceiver.
For the enable signal, the one with a horizontal line above the letter is valid at low level, and the one without it is valid at high level.

For the transmitter, there is the following truth table:
● When the driver enable pin DE is logic high, the differential outputs A and B follow the logic state at data input D. A logic high at D causes A to transition high and B to transition low. In this case, the differential output voltage defined as V O D = V A – V B V_{OD}=V_A–V_BVOD=VA–VB is positive. When D is low, the output state is reversed, B becomes high, A becomes low, and V O D V_{OD}VODis negative.
● When DE is low, both outputs become high impedance. In this case, the logic state at D is irrelevant.

For the receiver, there is the following truth table
● The receiver is activated when the receiver enable pin RE is logic low. When the differential input voltage defined as V I D = V A – V B V_{ID}=V_A–V_BVID=VA–VB is positive and higher than the positive input threshold V I T + V_{IT+}VIT+, the receiver output R becomes high. When V I D V_{ID}VID is negative and lower than the negative input threshold V I T − V_{IT-}VIT−, the receiver output R becomes low. If V I D V_{ID}VID is between V I T + V_{IT+}VIT+ and V I T − V_{IT-}VIT−, the output is undefined.
● When RE is logic high or floating, the receiver output is high impedance, and the size of V I D V_{ID}VID has nothing to do with the polarity.

RS-485 Receiver Truth Table
The standards of many transceivers meet or even exceed the TIA/EIA-485A specification. In actual use, the SPEC parameters of the device are mainly used.

TTL and RS-485 conversion
It is very common to convert TTL to RS-485. There are many transceiver chips on the market, such as MAX485, which are also very simple to use. Generally, the left side is connected to the GPIO of the MCU for control.

TTL to RS-485
RS-232 and RS-485 conversion
RS-232 and RS-485 can be converted. One method is to convert RS-232 to TTL, and then convert TTL to RS-485. Of course, there are also chips that support conversion of RS-232 to RS-485, bidirectional conversion.

RS-232 and RS-485 conversion module
IIC
Overview of IIC
The IIC bus is a simple, bidirectional two-wire synchronous serial bus developed by Philips. The IIC only requires two lines for communication, SDA (serial data line) and SCL (serial clock line)
The figure below is the typical structure of the I2C bus. At the same time, it can be a single host with multiple slaves or a single host with a single slave. Any device on the I2C bus can be a host. Generally, the host is an MCU. When there are multiple hosts, they will pass through the bus. Arbitration is used to select one master, and the others exit and become slaves.

IIC bus architecture
IIC rate
● Standard mode: 100Kbit/s
● Fast mode: 400Kbit/s
● High speed mode: 3.4Mbit/s
SPI
Overview of SPI
SPI is the abbreviation of Serial Peripheral Interface. It is a high-speed, full-duplex, synchronous communication bus. The speed of SPI is higher than that of I2C, generally reaching tens of Mbps. Different devices can be used as host and The speeds used as slaves are generally different.
SPI signal line
● MISO – Master Input Slave Output, master device data input, slave device data output;
● MOSI – Master Output Slave Input, master device data output, slave device data input;
● SCLK – Serial Clock, clock signal, generated by the master device;
● CS – Chip Select, slave device enable signal, controlled by the master device;
SPI typical applications
The most typical application of SPI is a single master and a single slave. The following figure shows the wiring method. Of course, multiple slaves can also be used.

SPI single master single slave connection method
For detailed knowledge about SPI, the blogger will update a blog introduction in the future.
CAN
CAN overview
CAN is the abbreviation of Controller Area Network. It is a serial communication network that effectively supports distributed control or real-time control. It is now a standard protocol for automotive networks.
CAN level logic
| level | logic | BusValue |
| dominant level | 0 | CAN_H=3.5V,CAN_L=1.5V |
| recessive level | 1 | CAN_H=2.5V,CAN_L=2.5V |
1-WIRE
1-WIRE Overview
The single bus is a peripheral serial expansion bus technology introduced by the American company DALLAS. It is different from SPI and I2C serial data communication methods. It uses a single signal line to transmit both clock and data, and the data transmission is bidirectional.
1-WIRE typical block diagram
The following is a typical block diagram of 1-WIRE. You can see that there is only one line between the microprocessor and the 1-WIRE device.
● When the MCU sends a logic 1, after passing through the inverter, the bus will show a logic 0. When the logic 0 passes through the inverter of the 1-WIRE device, a logic 1 will be received.
● When the MCU sends a logic 0, after passing through the inverter, the bus will present a logic 1. When the logic 1 passes through the inverter of the 1-WIRE device, a logic 0 will be received.
● In the same way, when the 1WIRE device sends a logic 1, the NMOS at the Tx will be turned on, and the bus will show a logic 0. After passing the inverter at the MCU Rx, the MCU will receive a logic 1.
● When sending a logic 0, the NMOS is turned off, the bus presents a logic 1, and the MCU will receive a logic 0.

1-WIRE structure diagram
Articles you may also like
Design of High Current H-Bridge Motor Drive Circuit
The working principle, key parameters, and selection of TVS
Understanding NAND Gate: The Universal Logic Gate in Digital Circuits
Gas Discharge Tube Symbols, Characteristics and Structure
-
nichicon
120µF 450V aluminum capacitor, 105°C rated, 7.5mm pitch, 2000h life, radial mount
