1. Basic principles of serial data communication
Computer data transmission has two modes: parallel and serial. The characteristics of parallel transmission are: each data bit is transmitted at the same time, with fast transmission speed and high efficiency. However, it requires more data lines, so the transmission cost is high. The distance of parallel data transmission is usually less than 30 meters. The characteristics of serial transmission are: data transmission is carried out in bit order, and at least one transmission line is required to complete it. The cost is low, but the speed is slow. The distance of serial data transmission can range from a few meters to thousands of kilometers.
1. Character format of asynchronous serial communication
Asynchronous serial data communication uses characters as units, that is, one character is transmitted at a time. The data format of asynchronous communication is:
One frame of information = 1 start bit (low level) + 5-8 data bits (following the start bit), indicating the valid data to be transmitted (low bit first) + 1 parity bit (optional) + 1, 1.5 or 2 stop bits (high level).
The time interval from the start bit to the stop bit is called a frame. It is the complete communication format of a character. Therefore, the character format of serial communication is also called the frame format.
2. Data path form of serial communication
Serial data communication has the following data path forms:
Simplex mode: A sends, B receives.
Half-duplex mode: A sends or receives, B receives or sends.
Full-duplex mode: A sends and receives, B receives and sends.
3. Serial communication transmission rate
The transmission rate is used to describe the speed of data transmission. In serial communication, data is transmitted bit by bit. Therefore, the transmission speed is expressed by the number of data bits transmitted per second, which is called the baud rate (Baud). One data bit transmitted per second is one baud. That is:
1 baud = 1bps (bit/second)
Commonly used baud rates are: 75, 110, 300, 600, 1200, 2400, 4800, 9600, 19200.
4. Serial communication interface circuit
There are two main technical issues in serial data communication:
Data transmission: Data transmission mainly solves problems such as standards, formats and working methods in transmission.
Data conversion: Data conversion refers to the serial-to-parallel conversion of data.
The basic logic block diagram of the serial interface circuit is as follows:
Serial input -> parallel output
Parallel input -> serial output
Clock, reset, control signal <-> status, control information
Universal Asynchronous Receiver Transmitter (UART) is a common interface for implementing asynchronous serial communication. Other common asynchronous serial communication interfaces include:
TTL level direct connection
RS-232C
RS-422, RS-485
20mA current loop
2. MCS-51 MCU serial port
The MCS-51 microcontroller has a full-duplex serial port that can be used for asynchronous serial communication and as a synchronous shift register. Timer T1 can be used as a serial communication baud rate generator.
1. Serial port register structure
The basic structure of the serial port of the MCS-51 microcontroller is as follows:
TXD serial output <- shift <- SBUF transmit register
RXD serial input -> shift -> SBUF receive register -> RI receive interrupt
Clock->Shift
SBUF is the buffer register of the serial port. It is a byte-addressable special register, which includes a send register (write only) and a receive register (read only), so that communication can be carried out in full-duplex mode. These two registers share the same address (99H).
For example:
Start sending: MOV SBUF, A; SBUF←(A)
Start receiving: MOV A, SBUF; A←(SBUF)
2. Registers related to serial communication
The special registers related to serial communication control are:
SCON: Serial control, used to set the working mode of the serial port
PCON: Power control, can control the baud rate.
IE: Set serial interrupt enable.
The format of the serial control register SCON (98H) is as follows:
SM0 SM1 SM2 REN TB8 RB8 TI RI
Function description:
SM0, SM1: Serial port working mode selection bits
00 Mode 0: Synchronous shift register, fixed baud rate.
01 Mode 1: 8-bit asynchronous, variable baud rate.
10 Mode 2: 9-bit asynchronous, fixed baud rate.
11 Mode 3: 9-bit asynchronous, variable baud rate.
SM2: Multi-machine communication control bit, mainly used in methods 2 and 3.
REN: Allow serial reception, set or cleared by software.
TB8/RB8:
In working modes 2 and 3, TB8 is the ninth bit of data sent, which is set (SETB TB8) or reset (CLR TB8) by software. In two-machine communication, this bit is used as a parity bit; in multi-machine communication, it is used to indicate that D7~D0 is an address frame or a data frame. That is: D8=0: indicates a data frame; D8=1: indicates an address frame.
RB8: In working modes 2 and 3, this bit is the 9th data bit received.
TI: Transmit interrupt flag. Before sending the stop bit, this bit is set by hardware to request an interrupt. After the CPU responds to the interrupt, the next frame of data can be sent. This bit must be cleared by software.
RI: Receive interrupt flag. When half of the stop bit is received, this bit is set by hardware (SM2 setting must also be considered), and an interrupt is requested. After the CPU responds to the interrupt, the next frame of data can be received. This bit must also be cleared by software.
The format of the power control register PCON (87H) is as follows:
SMOD - - - GF1 GF0 PD IDL
It is mainly used for power control of CHMOS type microcontrollers. For HMOS type microcontrollers, except for the highest bit (SMOD), all other bits are dummy. SMOD is the multiplication bit of the serial port baud rate.
When: SMOD = 1, the serial port baud rate is doubled. When the system is reset, SMOD = 0. It can be set by the following instructions:
MOV PCON, #80H; SMOD←1
MOV PCON, #00H; SMOD←0
3. How the serial port works
(1) Method 0
Mode 0 is the synchronous shift register mode. The RXD terminal is used as the entry or exit of data shift, and the TXD terminal provides the shift clock pulse. The transmission and reception of shifted data are based on 8 bits as a frame, without start bit and stop bit, the low bit is in front and the high bit is in the back, and the baud rate is fixed, which is fOSC/12. That is, one machine cycle shifts once.
Function: Used as I/O port expansion.
(2) Method 1
The frame format of mode 1 is: 1 start bit + 8 data bits + 1 stop bit.
Data transmission is started by a write transmit register (MOV SBUF, A) instruction. After that, the hardware automatically adds the start bit and stop bit to the serial port to form a complete frame format. Then, under the action of the shift pulse, it is serially output from the TXD terminal. After a character frame is sent, the TXD terminal output line is maintained at a high level, and TI is set to notify the CPU that the next character can be sent.
When receiving data, REN=1. Under this premise, the serial port samples the RXD terminal. When the sample jumps from 1 to 0, it is determined that the start bit is received. Then, under the control of the shift pulse, the received data is shifted into the receiving register. After the stop bit arrives, it is sent to RB8 and RI is set to notify the CPU to take a received character from SBUF.
The baud rate of mode 1 is variable and is determined by the following formula:
Baud rate = (2^SMOD)/32 * (T1 overflow rate)
= (2^SMOD)/32 * fOSC/(12*[256-X])
Among them: smod is the value of the highest bit of the PCON register, fOSC is the crystal frequency, and X is the initial count value when T1 works in mode 2 (8-bit automatic loading). In actual use, always determine the baud rate first, and then calculate the initial count value of T1. That is:
X = 256 - (2^SMOD) * fOSC/(384*baud rate)
(3) Method 2 and Method 3
When the serial port works in mode 2 or 3, it is a 9-bit asynchronous communication port. The information sent and received in one frame consists of 11 bits, namely:
1 start bit (0) + 8 data bits (D0 to D7) + 1 programmable bit (D8) + 1 stop bit (1)
The D8 bit can be used as a parity bit or a control bit. Its function is determined by the user. When transmitting, the programmable bit D8 (TB8) can be set to 0 (CLR TB8) or 1 (SETB TB8). When receiving, TB8 is sent to the RB8 bit in the SCON register.
The difference between methods 2 and 3 is the baud rate settings:
The baud rate of mode 2 is fixed. That is: baud rate = fosc/32 or fosc/64
The baud rate of mode 3 is variable. The calculation formula is the same as that of mode 1.
The following table lists some commonly used baud rates and corresponding time constant settings:
Baud rate | fosc | smod | Timer 1 mode | Time constant |
---|---|---|---|---|
1200 | 1.0592 | 0 | 2 | E8H |
2400 | 1.0592 | 0 | 2 | F4H |
4800 | 1.0592 | 0 | 2 | FAH |
9600 | 1.0592 | 0 | 2 | FDH |
19200 | 1.0592 | 1 | 2 | FDH |
The I/O port can be easily expanded by using serial port working mode 0.
Previous article:Chapter 3 MCS-51 Instruction System
Next article:Chapter 7 Interrupt System
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
- dsp6657 serial port learning
- Try the data visualization tool of visionseed in Ubuntu
- Help with AD9 package design
- 1. Unboxing and Review
- NXP PLC2366 Timer 2 Interrupt Program
- Use of Linux semaphores - code testing
- Free evaluation | Ateli AT-START-F403A helps you explore and discover ARM Cortex-M4F with FPU core
- How to configure the input and output of a GPIO in the TMS320C6000 series DSP?
- Working conditions and working characteristics of switching power supply
- Let’s discuss some common misunderstandings about GaN.