0. Serial communication
0. Data transmission mode of serial communication: simplex (one-way data transmission), half-duplex (non-simultaneous two-way transmission), full-duplex (simultaneous, two-way transmission)
1. According to the different communication methods, it is divided into synchronous communication and asynchronous communication.
Synchronous communication: All devices use the same clock, called the synchronous clock. When transmitting data, it is transmitted in units of several data characters (called data blocks). Each data block includes a synchronization character, a data block, and a check character CRC.
Asynchronous communication means that in serial communication, the receiving device and the sending device have their own clock signals. Asynchronous communication transmits data in characters, but the clock frequencies must remain consistent during communication.
2. Baud rate and bit rate
The baud rate is the amount of signals transmitted per second (unit: baud B), and the bit rate is the amount of signals transmitted per second (unit: bps). In the microcontroller, these two things are the same.
For example, if the data transmission rate of both parties is 240 characters per second, and each character contains 10 bits (1 start bit, 8 data bits, and 1 stop bit), then the baud rate is
240 × 10 = 2400b/s = 2400B
3. SCON (98H, bit addressable)
SM0 and SM1 are used to set the serial port working mode.
SM2 is set to send address or data when the serial port works in mode 2 or 3.
REN is the acceptance permission bit, and TB8 is the value of the ninth programmable bit in working modes 2 and 3.
TI is the transmit flag.
RI is the receive flag.
4. PCON (87H, not bit addressable)
The highest bit can be used to adjust the baud rate, and the lower bits are related to power management.
80C51 serial port working mode: (P3.0 is the displacement input RxD (low bit first), P3.1 is the displacement output TxD)
Working mode 0: (Synchronous) 8 bits of data are one frame, there is no stop bit and start bit, the condition for sending the serial port is TI = 0; the condition for receiving is RI = 0 and REN = 1 (allow acceptance bit).
The baud rate is fixed at fosc/12. RB8 is not used.
Working mode 1: (asynchronous) (used for dual-machine communication) 10 bits of data form a frame, the lowest bit is the start bit (0), and the highest bit is the stop bit (1). SM2 = 0, RB8 receives the stop bit. In fact, when sending, working mode 1 continuously shifts the data to the right to the TxD port (the highest bit is already set to 1), and then continuously fills 0 on the left, and TI = 1 after sending; when receiving, it is just the opposite. When receiving, it will fill 1 at the receiving port. Once a jump from 1-0 is found (the start bit is received), it starts to receive data until the received stop bit is 1, which means the received information is correct. Then RI = 1.
Working modes 2, 3: (asynchronous) (multi-machine communication), 11 bits of data per frame, in addition to the start bit and stop bit, it also includes a programmable bit. This bit is provided by TB8 of SCON and can be used for parity check. It can also be combined with SM2 for multi-machine communication. TB8 is set when sending and RB8 when receiving.
When SM2 = 0, data and address are accepted; when SM2 = 1, only address is accepted (reflected in that the RB8 bit of the received information must be 1 (indicating that it is an address))
Serial port baud rate calculation:
The baud rate of mode 0 is 1/12 of the crystal frequency.
The baud rate of mode 2 is: baud rate = (2SMOD/64) × fosc
The baud rate of mode 1 and mode 3 = (2SMOD / 32) × timer overflow rate (usually mode 2 is selected as the clock for mode 1 and mode 3)
Common baud rates (get familiar with them):
Serial communication programming example (note that you need to manually clear TI and RI)
(send)
MOV R0, #40H; Set the initial value of the data block address pointer
MOV R7, #10H; Set the initial value of the data block length
ALOOP3: MOV SBUF, @R0; send a data byte
JNB TI, $; Waiting for sending to complete
CLR TI ; Clear send flag
INC R0;Address unit plus 1
DJNZ R7, ALOOP3; Whether the entire data block has been sent
(take over)
MOV R0, #40H; Set the initial value of the data block address pointer
MOV R7, #10H; Set the initial value of the data block length
BLOOP3: JNZ RI, $; Waiting to receive information
CLR RI ; Clear the receive flag
MOX A, SBUF; read the contents of the receive buffer
MOX @R0, A; receive data dump
INC R0; storage unit plus 1
DJNZ R7, BLOOP3; Determine whether the data block has been received
In the master-slave multi-machine communication system composed of MCS-51, there is only one master machine and a maximum of 256 slave machines.
1. I^2C bus
The encoding content includes: device identification, pin level, and direction bit.
Two lines: SCL (clock line), SDA (data line), 9-bit data transmission format (the last acknowledge bit).
When SCL is high, the falling edge of SDA indicates start.
When SCL is high, the rising edge of SDA indicates stop.
Previous article:Principles of Single-Chip Microcomputers P3: 80C51 External Expansion System
Next article:Principles of Single-Chip Microcomputers P2: 80C51 External Interrupts and Timer Systems
Recommended ReadingLatest update time:2024-11-16 09:37
- Popular Resources
- Popular amplifiers
- 西门子S7-12001500 PLC SCL语言编程从入门到精通 (北岛李工)
- Siemens Motion Control Technology and Engineering Applications (Tongxue, edited by Wu Xiaojun)
- How to read electrical control circuit diagrams (Classic best-selling books on electronics and electrical engineering) (Zheng Fengyi)
- MCU C language programming and Proteus simulation technology (Xu Aijun)
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
- Electric energy measurement solution based on C2000 built-in 12-bit ADC
- How many memory wafers are used in STM32F0 and STM32F1 series?
- The stm32f103c8t6 core board is powered by two USB cables, and the program cannot start automatically
- [NUCLEO-F746ZG Learning] Construction Project-Based on RT-Thread
- Occupation and age
- I need help from a master who can use ADS software to make filters
- [Technical Tips] GigaDevice GD32VF103C-START Getting Started
- How to assign initial values to a continuous RAM range in C2000 chip
- What is 4G DTU and what are its specific functions?
- CadenceLIVE China 2022 China Online User Conference invites you to attend