1. References
"STM32F1 Development Guide - Library Function Version" - 5.3 usart serial port folder introduction
- Chapter 9 Serial Port Experiment
"STM32 Chinese Reference Manual V10" - Chapter 25 Universal Synchronous Asynchronous Receiver Transmitter (USART)
2. Basic principles of serial communication
Commonly used serial port related registers
USART_SR status register
USART_DR data register
USART_BRR baud rate register
Serial port operation related registers (entry parameters omitted):
void USART_Init(); //Serial port initialization: baud rate, data word length, parity check, hardware flow control and transmit and receive enable
void USART_Cmd(); //Enable serial port
void USART_ITConfig(); //Enable related interrupts
void USART_SendData(); //Send data to the serial port, DR
uint16_t USART_ReceiveData(); //Receive data and read the received data from DR
FlagStatus USART_GetFlagStatus(); //Get the status flag
void USART_ClearFlag(); //Clear status flag
ITStatus USART_GetITStatus(); //Get interrupt status flag
void USART_ClearITPendingBit(); //Clear interrupt status flag
Status Register (USART_SR)
FlagStatus USART_GetFlagStatus(USART_TypeDef* USARTx, uint16_t USART_FLAG);
Data register (USART_DR)
void USART_SendData(USART_TypeDef* USARTx, uint16_t Data);
uint16_t USART_ReceiveData(USART_TypeDef* USARTx);
Baud Rate Register (USART_BRR)
void USART_Init(USART_TypeDef* USARTx, USART_InitTypeDef* USART_InitStruct);
Baud rate calculation method
Hardware Connection
PA9, PA10 (serial port 1) are connected to the USB serial port circuit
3. General steps for serial port configuration
①Serial port clock enable, GPIO clock enable: RCC_APB2PeriphClockCmd();
②Serial port reset: USART_DeInit(); This step is not necessary
③GPIO port mode setting: GPIO_Init(); mode is set to GPIO_Mode_AF_PP
④Serial port parameter initialization: USART_Init();
⑤ Enable interrupts and initialize NVIC (this step is required only if interrupts need to be enabled)
NVIC_Init();
USART_ITConfig();
⑥ Enable the serial port: USART_Cmd();
⑦Write interrupt handling function: USARTx_IRQHandler();
⑧Serial port data transmission and reception:
void USART_SendData(); //Send data to the serial port, DR
uint16_t USART_ReceiveData(); //Receive data and read the received data from DR
⑨Serial port transmission status acquisition:
FlagStatus USART_GetFlagStatus(USART_TypeDef* USARTx, uint16_t USART_FLAG);
void USART_ClearITPendingBit(USART_TypeDef* USARTx, uint16_t USART_IT);
Previous article:STM32 serial port basic configuration (register version) notes
Next article:STM32F103 USART serial port simple implementation
Recommended ReadingLatest update time:2024-11-16 13:55
- Popular Resources
- Popular amplifiers
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
- [Hua Diao Experience] 06 Building a Xingkong board development environment - Thonny programming
- The most comprehensive collection of circuit postgraduate entrance examination questions and tutorials, a benefit for postgraduate entrance examination candidates!
- GD32E231C_START ADC code evaluation
- TMS320F28335 project development record 11_28335 storage system
- Things you must know about Gallium Nitride (GaN): Technology (Part 2)!
- MC34063A step-down circuit chip cooling
- SinlinxA33 Simple QT control LED (io control)
- Can CycloneIII FPGA lock JTAG?
- "Playing with the board" + Yu Zhennan's STM32 development board experiment 3
- 【NUCLEO-L552ZE Review】2. Resources