Computer communication is the combination of computer technology and communication technology to complete the information exchange between computers and external devices or between computers. It can be divided into two categories: parallel communication and serial communication.
Parallel communication usually involves transmitting each bit of a data byte simultaneously using multiple data lines.
Parallel communication has simple control and fast transmission speed; however, due to the large number of transmission lines, the cost is high for long-distance transmission and it is difficult for all receivers to receive simultaneously.
Serial communication is the process of dividing data bytes into bits and transmitting them one by one on a transmission line.
Characteristics of serial communication: fewer transmission lines, low cost for long-distance transmission, and the ability to utilize existing equipment such as telephone networks, but data transmission control is more complex than parallel communication.
Basic concepts of serial communication
1. Asynchronous communication and synchronous communication
1. 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".
Data format for asynchronous communication:
Characteristics of asynchronous communication: It does not require strict consistency of the clocks of the sender and receiver, is easy to implement, and has low equipment overhead, but each character must be added with 2 to 3 bits for start and end bits, and there are intervals between frames, so the transmission efficiency is not high.
2. 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 and the receiver can be achieved in two ways.
External synchronization Self-synchronization
Serial communication transmission direction
Simplex means that data can only be transmitted in one direction and reverse transmission is not possible.
Half-duplex means that data transmission can be carried out in both directions, but it needs to be done in time.
Full-duplex means that data can be transmitted in both directions simultaneously.
Common error checking in serial communication
1. Parity check
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.
2. 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.
3. 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.
Transmission rate
The bit rate (baud rate) is the number of bits of binary code transmitted per second, and the unit is: bit/second (bps). For example, if 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 (baud rate) at this time is: 10 bits × 240/second = 2400 bps
89C52 serial port
89C52 serial port structure
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.
89C52 serial port control register
SM0 and SM1 are the working mode selection bits, and four working modes can be selected:
SM2, multi-machine communication control bit, is mainly used in mode 2 and mode 3. When the receiver's SM2=1, the received RB8 can be used to control whether to activate RI (when RB8=0, RI is not activated and the received information is discarded; when RB8=1, the received data enters SBUF and activates RI, and then the data is read from SBUF in the interrupt service). When SM2=0, regardless of whether the received RB8 is 0 or 1, the received data can enter SBUF and activate RI (that is, RB8 does not have the function of controlling RI activation at this time). By controlling SM2, multi-machine communication can be achieved. 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 reception enable bit. If software sets REN=1, the serial port starts receiving data; if software sets REN=0, reception is disabled.
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 the data, or as the flag bit of the address frame/data frame in multi-machine communication. In mode 0 and mode 1, this bit is not used.
RB8, in Mode 2 or Mode 3, is the ninth bit of the received data and serves as a parity bit or a flag bit for the address frame/data frame. 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 program, it must be cleared to 0 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 to 1 and sends an interrupt request to the CPU. It must also be cleared to 0 by software in the interrupt service routine to cancel this interrupt request.
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.
How the serial port works
1. Method 0
In mode 0, the serial port is the input and output mode of the synchronous shift register. It is mainly used to expand the parallel input or output port. 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 to fosc/12.
1. Mode 0 output:
2. Mode 0 input:
Method 1
Mode 1 is an asynchronous communication port with 10-bit data. TXD is the data transmission pin, RXD is the data reception pin, and the format of transmitting a frame of data is shown in the figure. There is 1 start bit, 8 data bits, and 1 stop bit.
1. Mode 1 output:
2. Method 1 input:
When REN is set to 1 by software, the receiver samples the RXD pin level at a rate 16 times the selected baud rate. When a negative jump is detected in the input level of the RXD pin, it means that the start bit is valid, and it is shifted into the input shift register, and the remaining bits of this frame information are received. During the reception process, the data is shifted in from the right side of the input shift register. When the start bit is moved to the leftmost side of the input shift register, the control circuit performs the last shift. When RI=0 and SM2=0 (or the received stop bit is 1), the first 8 bits of the received 9-bit data are loaded into the receiving SBUF, the 9th bit (stop bit) enters RB8, and RI=1 is set to request an interrupt to the CPU.
Method 2 and Method 3:
In mode 2 or mode 3, it is an asynchronous communication port for 11-bit data. TXD is the data transmission pin, and RXD is the data reception pin.
In mode 2 and mode 3, the start bit is 1 bit, the data is 9 bits (including the 1-bit additional 9th bit, which is TB8 in SCON when sending and RB8 when receiving), the stop bit is 1 bit, and a frame of data is 11 bits. The baud rate of mode 2 is fixed to 1/64 or 1/32 of the crystal frequency, and the baud rate of mode 3 is determined by the overflow rate of timer T1.
The difference between Mode 2 and Mode 3 is the baud rate selection method. In both modes, the received stop bit has nothing to do with SBUF, RB8 and RI.
Baud rate calculation
In serial communication, the sender and receiver must agree on the rate at which data is sent or received. The microcontroller serial port can be programmed into four working modes through software, of which mode 0 and
Previous article:51 MCU Experiment 7: Matrix Buttons
Next article:51 MCU Experiment 11: Serial Communication
- Naxin Micro and Xinxian jointly launched the NS800RT series of real-time control MCUs
- How to learn embedded systems based on ARM platform
- Summary of jffs2_scan_eraseblock issues
- Application of SPCOMM Control in Serial Communication of Delphi7.0
- Using TComm component to realize serial communication in Delphi environment
- Bar chart code for embedded development practices
- Embedded Development Learning (10)
- Embedded Development Learning (8)
- Embedded Development Learning (6)
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- Intel promotes AI with multi-dimensional efforts in technology, application, and ecology
- ChinaJoy Qualcomm Snapdragon Theme Pavilion takes you to experience the new changes in digital entertainment in the 5G era
- Infineon's latest generation IGBT technology platform enables precise control of speed and position
- Two test methods for LED lighting life
- Don't Let Lightning Induced Surges Scare You
- Application of brushless motor controller ML4425/4426
- Easy identification of LED power supply quality
- World's first integrated photovoltaic solar system completed in Israel
- Sliding window mean filter for avr microcontroller AD conversion
- What does call mean in the detailed explanation of ABB robot programming instructions?
- CATL releases October battle report
- Battery industry in October 2024: growth momentum remains unabated!
- Mercedes-Benz will launch the eCitaro equipped with NMC4 batteries to provide high energy density and long life
- Many companies have announced progress on solid-state batteries. When will solid-state batteries go into mass production?
- Xsens Sirius Series Inertial Sensors Enable 3D Inertial Navigation in Harsh Environments
- Infineon's Automotive Landscape: From Hardware to Systems
- STMicroelectronics discloses its 2027-2028 financial model and path to achieve its 2030 goals
- 2024 China Automotive Charging and Battery Swapping Ecosystem Conference held in Taiyuan
- State-owned enterprises team up to invest in solid-state battery giant
- The evolution of electronic and electrical architecture is accelerating
- Do you still take notes? How do you do it? Can you recommend a note-taking tool?
- Sipeed GW2A PLL simple use
- Sipeed GW2A SVPWM Wave Test
- [Beineng cost-effective ATSAMD51 evaluation board] KEIL environment construction/light up LED0/make LED flash
- Recommend a very good freertos learning material
- [Vote to share a 2,500 yuan red envelope] The 2022 Digi-Key Innovation Design Competition Outstanding Work Popularity Award is decided by you!
- What GaN innovations will emerge in the next few years?
- MicroPython Wifi Robot Car
- [MPS Mall Big Discount Experience Season] Unboxing - Finally received the goods
- Reproduce a small TV, share it, and do research at the same time