Ⅰ. Write in front
People who do software development know the importance of printing information. When it comes to printing information, we have to talk about UART serial port printing. For people who do microcontroller development, the main source of printing information is UART serial port printing. Therefore, knowledge about UART is more important.
Standard functions such as printf and scanf can not only be used on computers, but also on our microcontrollers. This article only describes the basic knowledge about UART. I will write another article about printf and scanf later.
This article will combine the "STM8S Reference Manual" and software source code to tell you the basic knowledge and usage of UART.
For your convenience, the content of this article has been organized into a PDF file:
http://pan.baidu.com/s/1i5uWhJR
Author:strongerHuang
All rights reserved. Any other commercial use is prohibited without permission!!!
Ⅱ. UART Basics
Universal Asynchronous Receiver/Transmitter (Universal Asynchronous Receiver/Transmitter), commonly known as UART, is an asynchronous receiver/transmitter.
The universal synchronous asynchronous receiver/transmitter (UART1, UART2 or UART3) of the STM8S microcontroller family provides a flexible method for full-duplex data exchange with external devices using the industry standard NZR asynchronous serial data format. The STM8 UART provides a wide range of baud rate selections and supports multi-processor communication.
Key Features:
Ø Full-duplex, asynchronous communication
Ø High-precision baud rate generator system: programmable baud rate for both sending and receiving, up to 2.5Mbits/s
Ø Programmable data word length (8 bits or 9 bits)
Configurable stop bits - supports 1 or 2 stop bits
Ø Single-line half-duplex communication (UART1)
Ø Detection flag: receive buffer full, send buffer empty, transmission end flag
Ø 6 interrupt sources with flags
Ø 2 interrupt vectors
Ø Low power mode
UART Synchronous Mode
The UART_CK pin is the output of the UART transmitter clock. There is no clock pulse on the UART_CK pin during the start and stop bits. Depending on the state of the LBCL bit in the UART_CR3 register, the transmitter decides to generate or not generate a clock pulse during the last valid data bit. The CPOL bit in the UART_CR3 register allows the user to select the clock polarity, and the CPHA bit in the UART_CR3 register allows the user to select the phase of the external clock.
In the bus idle frame and disconnect frame, the external CK clock is inactive.
Notice:
1.UART_CK pin works together with UART_TX pin. When the UART transmitter is disabled (TEN and REN = 0), UART_CK and UART_TX pins are in high impedance state.
2. When both the transmitter and receiver of the UART are disabled (TEN=REN=0), the LBCL, CPOL and CPHA bits must be configured correctly to ensure that the clock pulse works correctly; these bits cannot be changed when the transmitter or receiver is activated.
3. It is recommended to set TE and RE in the same instruction to reduce the receiver's setup time and hold time.
4. UART only supports master mode: it cannot use the input clock from other devices to receive or send data (SCLK can only be configured as output state).
5. The data given in this section is valid only when UART_DIV[3:0] in register UART_BRR2 is 0. Otherwise, the setup time and duration are no longer 1/16 bit time, but 4/16 bit time.
This function option can serially control peripherals composed of shift registers without losing the asynchronous communication function, that is, it can still communicate with other asynchronous transmitters and receivers.
UART synchronous transmission example:
III. Software Engineering Source Code
1. About the project
The engineering code provided in this article is based on the previous software project "STM8S-A02_TIM Precise Delay (Blocking)" and modified to add UART serial port. Beginners can refer to my previous corresponding basic articles, which are more detailed.
The source code of the project mainly implements the following functions: UART serial port basic output + interrupt receiving data. The UART serial port prints the string "Demo..." at an interval of 1s. The serial port receives data through interrupts, and sends a character through the serial port when it is received.
This article focuses on the following contents about UART:
UART_Initializes: UART serial port initialization
UART1_SendByte: UART serial port sends byte data
2. Code Analysis Description
A.UART_Initializes: Initialization
void UART_Initializes(void)
{
UART1_Init((uint32_t)115200,UART1_WORDLENGTH_8D,UART1_STOPBITS_1,UART1_PARITY_NO, UART1_SYNCMODE_CLOCK_DISABLE, UART1_MODE_TXRX_ENABLE);
http://pan.baidu.com/s/1o7Tb9Yq
Software source code project (STM8S-A04_UART basic data transmission and reception):
http://pan.baidu.com/s/1c2EcRo0
Previous article:STM8S_005_ADC collects single channel voltage
Next article:STM8S_003_TIM timing interrupt
Recommended ReadingLatest update time:2024-11-16 08:59
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
- [STM32WB55 Review] 3# STM32WB development board boot sequence and radio module
- First unpacking test
- Output adjustable solution
- bq769x0, recharging problem after undervoltage
- TMS320F28379D User Experience SCI
- Respeaker Mic array Far-field microphone array AI intelligent voice recognition module
- What should I do if there are multiple initialization and redefinition errors? Please give me some advice
- The difference between electrolytic capacitors and ordinary ceramic capacitors of the same capacity
- The microcontroller gadgets I collected before are very convenient!!!
- Future Transformer Development Trend-Planar Transformer