When writing the sending code with reference to the official USART example, the first character of the string is inexplicably lost
Keywords:USART
Reference address:Reasons and solutions for the loss of the first character of a string sent by USART
/* eg write a character to the USART */
USART_SendData(EVAL_COM1, (uint8_t) ch);
/* Loop until the end of transmission */
while (USART_GetFlagStatus(EVAL_COM1, USART_FLAG_TC) == RESET)
{}
After looking through the data sheet, I found that the TXE and TC flags are set to 1 by default after reset, which causes the first flag detection to fail and the first character is overwritten before it is sent.
Once the cause is found, the solution is quite simple. Just clear the flag bit before sending the first character.
Two methods:
1. Change the TC detection to the TXE inspection
while (USART_GetFlagStatus(EVAL_COM1, USART_FLAG_TXE) == RESET)
2. Before writing data to the USART_DR register, read the USART_SR register once
/* Read USART_SR register */ USARTx -> SR; /* eg write a character to the USART */ USART_SendData(EVAL_COM1, (uint8_t) ch); /* Loop until the end of transmission */ while (USART_GetFlagStatus(EVAL_COM1, USART_FLAG_TC ) == RESET) {}
Previous article:stm32f051 key control (3)
Next article:STM32 clock tree analysis
Recommended ReadingLatest update time:2024-11-16 12:58
STM32F103xC USART/UART decomposition
Chip: STM32F103RCT6 (64pin, 256K, LQFP, -40~85) Object: USART The STM32F103xC chip embeds three universal synchronous/asynchronous receiver transmitters (USART1, USART2 and USART3) and two universal asynchronous receiver transmitters (UART4 and UART5). These five interfaces provide asynchronous communi
[Microcontroller]
STM32 USART2 sends data notes
Hardware device: STM32VCT6 GPIO_InitTypeDef GPIO_InitStructure; USART_InitTypeDef USART_InitStructure; RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE); //使能GPIOA时钟 RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2, ENABLE); //使能USART2时钟 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2; GPIO_InitStructure.GPIO_Speed = GPIO
[Microcontroller]
STM32F0 USART wakeup from STOP mode
Recently, I am considering using the STM32F030/042 series to make some low-power products, such as the 433/315 copy-type remote control paired with the car navigation, which requires serial communication and STOP mode. But the annoying thing is that the built-in serial port wake-up function of the STM32F0 seri
[Microcontroller]
STM32_USART serial communication detailed explanation
Anyone who knows about 51 MCU knows the working principle of serial communication of 51 MCU. Our MCU uses TTL level. In order to make our MCU communicate with PC, we need a level conversion chip to convert TTL level to USB level (USB interface is used. If DB9 interface is used, the level conversion chip is TTL to RS23
[Microcontroller]
Initialization of ATmega32 USART
ATmega32 must first initialize USART before communicating. The initialization process usually includes setting the baud rate, setting the frame structure, and enabling the receiver or transmitter as needed. For interrupt-driven USART operation, the global interrupt flag must be cleared first during initialization (glo
[Microcontroller]
Recommended Content
Latest Microcontroller Articles
He Limin Column
Microcontroller and Embedded Systems Bible
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
MoreSelected Circuit Diagrams
MorePopular Articles
- 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
MoreDaily News
- 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
Guess you like
- Recommend an FPGA development board, with schematic diagram
- [Mil MYS-8MMX] Mil MYS-8MMQ6-8E2D-180-C National Day Application - Use the terminal to draw
- FAQ: Developing secure IoT edge-to-cloud applications on Linux using PKCS #11 and secure devices
- CC2640 TIRTOS adds IIC configuration
- ARM co-founder launches "SAVE ARM" campaign to intervene in NVIDIA acquisition
- How to convert PWM signal into analog signal
- Uf2 Introduction
- Wi-Fi-7?
- Analog Series: RF: In the 5G Era, RF Front-End Shines
- FPGA Design Tips