1. Know before you know
1. Basics of computing serial communication
2. Basic concepts of serial communication
(1) Asynchronous communication and synchronous communication
a. Asynchronous communication
Asynchronous communication refers to the process in which the sending and receiving devices use their own clocks to control the sending and receiving of data. In order to coordinate the sending and receiving of both parties, the clocks of the sending and receiving devices are required to be as consistent as possible.
Asynchronous communication is transmitted in units of characters (frames). The gaps (time intervals) between characters are arbitrary, but each bit in each character is transmitted at a fixed time. That is, the characters are not necessarily related by an integer multiple of the "bit interval", but the distances between each bit in the same character are all integer multiples of the "bit interval".
b. Synchronous communication
In synchronous communication, the sender's clock directly controls the receiver's clock so that both parties are completely synchronized. At this time, the distance between the bits of the transmitted data is an integer multiple of the "bit interval", and there is no gap between the transmitted characters, that is, the bit synchronization relationship is maintained, and the character synchronization relationship is also maintained. The synchronization of the sender to the receiver can be achieved in two ways.
(2) Transmission direction of serial communication
Simplex: Data transmission can only be in one direction and cannot be reversed;
Half-duplex: Data transmission can be in both directions, but it needs to be done in time division;
Full-duplex: Data can be transmitted in both directions simultaneously.
(3) Common error checking in serial communication
Parity
When sending data, the 1 bit following the data bit is the parity bit (1 or 0). When odd parity is used, the sum of the number of "1"s in the data and the number of check bits "1" should be an odd number; when even parity is used, the sum of the number of "1"s in the data and the number of check bits "1" should be an even number. When receiving characters, the number of "1"s is checked. If it is inconsistent, it means that an error has occurred during the data transmission process.
Code and verification
The code and checksum is that the sender sums the data block (or XORs each byte) to generate a one-byte checksum character (checksum) and appends it to the end of the data block. The receiver receives the data and sums the data block (except the check byte) (or XORs each byte), and compares the result with the sender's "checksum". If they match, there is no error. Otherwise, it is considered that an error occurred during the transmission process.
Cyclic Redundancy Check
This type of verification is a cyclic verification between valid information and check bits through some mathematical operations, which is often used for transmission of disk information, integrity verification of storage areas, etc. This verification method has strong error correction capability and is widely used in synchronous communications.
Parity check is usually used, and the others are understandable.
(4) Transmission rate
Bit rate (also known as baud rate), the number of bits of binary code transmitted per second, the unit is: bits/second (bps).
240 characters are transmitted per second, and each character format contains 10 bits (1 start bit, 1 stop bit, 8 data bits). The bit rate is: 10 bits × 240/second = 2400 bps
(5) Relationship between transmission distance and transmission rate
The maximum distance that a serial interface or terminal can directly transmit a serial information bit stream is related to the transmission rate and the electrical characteristics of the transmission line. When the transmission line uses an unbalanced shielded twisted pair with a 50PF capacitance per 0.3 meter (about 1 foot), the transmission distance decreases as the transmission rate increases. When the bit rate exceeds 1000bps, the maximum transmission distance drops rapidly.
At 9600bps, the maximum distance drops to only 76m (about 250 feet).
That is to say, [the greater the transmission speed, the smaller the transmission distance].
(6) Serial communication interface standards
a. RS-232C interface
RS-232C is the RS-232C standard revised by EIA (Electronic Industries Association) in 1969. RS-232C defines the physical interface standard between data terminal equipment (DTE) and data communication equipment (DCE).
<1> Mechanical properties
The RS-232C interface specifies the use of a 25-pin connector, with the connector size and the arrangement of each pin clearly defined. (Male)
<2>, Functional characteristics
<3>, Process characteristics
Process characteristics dictate the timing relationships between signals so that data can be received and sent correctly.
Note: Send and receive are connected, don't connect them wrongly
b. RS-232C level and TTL level conversion drive circuit
The MC1488 chip converts the TTL level to the RS-232 level, that is, converts 5V to 12V for communication.
The MC1489 chip converts the RS-232 level into the TTL level, that is, converts 12V into 5V for communication.
c.RS422A interface
The RS-422A output driver is a double-ended balanced driver. If one line is in the logic "1" state, the other line is in the logic "0", which is twice as large as the voltage amplification of a single-ended unbalanced driver. The differential circuit can pick up valid signals from ground interference, and the differential receiver can distinguish potential differences of more than 200mV. If interference and noise are mixed in the transmission process, the interference and noise can be offset by each other due to the effect of the differential amplifier. Therefore, the influence of ground interference and electromagnetic interference can be avoided or greatly reduced. When the RS-422A transmission rate (90Kbps) is used, the transmission distance can reach 1200 meters.
d.RS-485 interface
RS-485 is a variation of RS-422A: RS-422A is used for full-duplex, while RS-485 is used for half-duplex. RS-485 is a multi-transmitter standard that can use up to 32 pairs of differential drivers/receivers on the communication line. If more than 32 devices are connected in a network, repeaters can also be used.
RS-485 uses voltage between two lines to represent logic 1 and logic 0. Since the sender needs two transmission lines, the receiver also needs two transmission lines. The transmission line uses a differential channel, so it has excellent interference suppression. Because of its low impedance and no grounding problem, the transmission distance can reach 1200 meters and the transmission rate can reach 1Mbps.
2. Serial port of 80C51
1. Structure of 80C51 serial port
There are two physically independent receive and transmit buffers SBUF, which occupy the same address 99H; the receiver is a double buffer structure; the transmit buffer, because the CPU is active during transmission, will not cause overlap errors.
2. Register SCON
SCON is a special function register used to set the serial port's operating mode and receive/send control.
It sets the status flags:
SM0 and SM1 are the working mode selection bits, and four working modes can be selected:
Common usage 1
SM2, multi-machine communication control bit, is mainly used in mode 2 and mode 3.
When the receiver's SM2=1, RB8 can be used to control whether to activate RI
RB8=0, RI is not activated, and the received information is discarded;
RB8=1, the received data enters SBUF, and RI is activated, and the data is read from SBUF in the interrupt service.
When SM2=0, no matter whether the received RB8 is 0 or 1, the received data can enter SBUF and activate RI. (That is, RB8 does not control the activation of RI at this time). [By controlling SM2, multi-machine communication can be achieved].
**Note:** In mode 0, SM2 must be 0; in mode 1, if SM2=1, RI is set to 1 only when a valid stop bit is received.
REN, serial receive enable bit.
When software sets REN=1, the serial port starts receiving data.
If the software sets REN=0, the binary reception is performed.
TB8, in mode 2 or mode 3, is the ninth bit of the transmitted data and its function can be defined by software.
It can be used as the parity bit of data or as the flag bit of address frame/data frame in multi-machine communication. (This bit is not used in mode 0 and mode 1)
RB8, in Mode 2 or Mode 3, is the ninth bit of the received data.
As parity bit or address frame/data frame flag bit. (In mode 1, if SM2=0, RB8 is the received stop bit.
TI, transmit interrupt flag.
In mode 0, when the serial transmission of the 8th bit of data ends, or in other modes, when the serial transmission of the stop bit begins, the internal hardware sets TI to 1 and sends an interrupt request to the CPU. In the interrupt service routine, it must be cleared by software to cancel the interrupt request.
RI, receive interrupt flag.
In mode 0, when the serial reception of the 8th bit of data is completed, or in other modes, when the serial reception is in the middle of the stop bit, the internal hardware sets RI=1 and sends an interrupt request to the CPU. It must also be cleared by software in the interrupt service routine to cancel this interrupt.
3. Register PCON
There is only one SMOD in PCON that is related to the serial port operation:
SMOD (PCON.7) Baud rate multiplication bit. In serial port mode 1, mode 2, mode 3, the baud rate is related to SMOD. When SMOD=1, the baud rate is doubled. When reset, SMOD=0.
3. How the serial port works
1. Method 0
a. Output
In mode 0, the serial port is in the input and output mode of synchronous shift register. It is mainly used to expand parallel input or output ports.
Data is input or output by the RXD (P3.0) pin, and the synchronous shift pulse is output by the TXD (P3.1) pin. Both sending and receiving are 8-bit data, with the low bit first and the high bit later. The baud rate is fixed at fosc/12.
1. Mode 0 output
Previous article:[MCU Learning] 51 MCU [Timer/Counter], detailed introduction
Next article:[MCU Learning] 51 MCU [Interrupt System], detailed introduction
Recommended ReadingLatest update time:2024-11-16 10:35
- Popular Resources
- Popular amplifiers
- Wireless Sensor Network Technology and Applications (Edited by Mou Si, Yin Hong, and Su Xing)
- Modern Electronic Technology Training Course (Edited by Yao Youfeng)
- Modern arc welding power supply and its control
- Small AC Servo Motor Control Circuit Design (by Masaru Ishijima; translated by Xue Liang and Zhu Jianjun, by Masaru Ishijima, Xue Liang, and Zhu Jianjun)
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- Innolux's intelligent steer-by-wire solution makes cars smarter and safer
- 8051 MCU - Parity Check
- How to efficiently balance the sensitivity of tactile sensing interfaces
- What should I do if the servo motor shakes? What causes the servo motor to shake quickly?
- 【Brushless Motor】Analysis of three-phase BLDC motor and sharing of two popular development boards
- Midea Industrial Technology's subsidiaries Clou Electronics and Hekang New Energy jointly appeared at the Munich Battery Energy Storage Exhibition and Solar Energy Exhibition
- Guoxin Sichen | Application of ferroelectric memory PB85RS2MC in power battery management, with a capacity of 2M
- Analysis of common faults of frequency converter
- In a head-on competition with Qualcomm, what kind of cockpit products has Intel come up with?
- Dalian Rongke's all-vanadium liquid flow battery energy storage equipment industrialization project has entered the sprint stage before production
- Allegro MicroSystems Introduces Advanced Magnetic and Inductive Position Sensing Solutions at Electronica 2024
- Car key in the left hand, liveness detection radar in the right hand, UWB is imperative for cars!
- After a decade of rapid development, domestic CIS has entered the market
- Aegis Dagger Battery + Thor EM-i Super Hybrid, Geely New Energy has thrown out two "king bombs"
- A brief discussion on functional safety - fault, error, and failure
- In the smart car 2.0 cycle, these core industry chains are facing major opportunities!
- The United States and Japan are developing new batteries. CATL faces challenges? How should China's new energy battery industry respond?
- Murata launches high-precision 6-axis inertial sensor for automobiles
- Ford patents pre-charge alarm to help save costs and respond to emergencies
- New real-time microcontroller system from Texas Instruments enables smarter processing in automotive and industrial applications
- MCO (PA8) does not output waveform during DEBUG. What is the reason?
- [Fudan Micro FM33LC046N Review] + Unboxing & Preparation of Related Documents
- When the power is turned on, there is only one puff of smoke and several days of hard work are wasted.
- Request the chip information (such as model) as shown in the picture
- Share a domestic chip 32-bit M4 microcontroller - AT32F403A series
- Patch reverse check
- TI C6000 project creation steps
- Please teach me a peak detection circuit composed of an op amp
- EEWORLD University ---- Control system of 100 quantum bits
- What is the function of this solder joint on the PCB?