The USART_IT_RXNE register generates an interrupt when a byte is not received, while the USART_IT_IDLE register generates an interrupt after receiving a complete frame, that is, an interrupt will be generated if no more is received within one byte after receiving a byte.
Here is the source code:
void USART1_Config(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
USART_InitTypeDef USART_InitStructure; //Define the serial port initialization structure
NVIC_InitTypeDef NVIC_InitStruct;
RCC_AHBPeriphClockCmd(USART1_GPIO_RCC, ENABLE); //Enable GPIOA clock
RCC_APB2PeriphClockCmd(USART1_RCC, ENABLE); //Enable USART clock
GPIO_PinAFConfig(USART1_GPIO_PORT, USART1_TX_GPIO_PinSource, GPIO_AF_1); //Configure PA9 as the second function pin TX
GPIO_PinAFConfig(USART1_GPIO_PORT, USART1_RX_GPIO_PinSource, GPIO_AF_1); //Configure PA10 as the second function pin RX
/*USART1_TX ->PA9 USART1_RX ->PA10*/
GPIO_InitStructure.GPIO_Pin = USART1_TX|USART1_RX; //Select the default output pin of the serial port
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF; //Define the maximum output rate
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; //Define the mode of pin 9
GPIO_Init(USART1_GPIO_PORT, &GPIO_InitStructure); //Call the function and input the structure parameters for initialization
/*Serial port communication parameter settings*/
USART_InitStructure.USART_BaudRate = UART1_BaudRate;//9600; //Baud rate
USART_InitStructure.USART_WordLength = USART_WordLength_8b; //8 data bits
USART_InitStructure.USART_StopBits = USART_StopBits_1; //Stop bit 1
USART_InitStructure.USART_Parity = USART_Parity_No; //No parity bit
USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;//No flow control
USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx; //Enable receive and transmit pins
USART_Init(USART1, &USART_InitStructure);
//USART_ClearFlag(USART1,USART_FLAG_TC);
USART_ITConfig(USART1, USART_IT_RXNE, ENABLE);
USART_ITConfig(USART1, USART_IT_IDLE, ENABLE);
USART1->ICR |= 1<<4; //The IDLE interrupt must be cleared first, otherwise it will continue to enter the IDLE interrupt
USART_Cmd(USART1, ENABLE);
/* NVIC interrupt configuration for USART1 */
NVIC_InitStruct.NVIC_IRQChannel = USART1_IRQn;
NVIC_InitStruct.NVIC_IRQChannelPriority = 0x02;
NVIC_InitStruct.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStruct);
}
/**
* @file USART1_IRQHandler
* @brief USART1 interrupt handling
* @param None
* @retval None
*/
void USART1_IRQHandler(void)
{
uint32_t temp = 0;
if(USART_GetITStatus(USART1, USART_IT_RXNE) != RESET)
{
//USART_SendData(USART1,USART_ReceiveData(USART1));
if (uart_recv[UART_1].count < UART_BUF_LEN)
{
//uart_recv_flag = 1;
uart_recv[UART_1].recv_buf[uart_recv[UART_1].count] = USART_ReceiveData(USART1);
uart_recv[UART_1].count++;
}
while (USART_GetFlagStatus(USART1,USART_FLAG_TXE) == RESET);
}
if(USART_GetITStatus(USART1, USART_IT_IDLE) != RESET)
{
USART1->ICR |= 1<<4;
uart_recv_flag = 1;
UART_send(USART1, "hello", sizeof("hello"));
}
}
Note that the method to clear the interrupt of F0 chip is to use the ICR register. After enabling the interrupt, you must clear the interrupt immediately, otherwise it will keep entering the interrupt.
Previous article:stm32 USART receive bus idle interrupt --USART_IT_IDLE
Next article:Pay attention to the IDLE interrupt of STM32F series USART
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
- Interest group training topic: Use MOS tube or + op amp to realize a DC/DC closed-loop voltage regulator
- Simple square wave generator based on 51 single chip microcomputer
- MSP430fr6989 serial port DMA sending experimental routine
- [RISC-V MCU CH32V103 Review] First impression of CH32V103C8T6 chip
- 100 check items for PCB design to ensure you have no problems with your design!
- How to write the corresponding program process according to the timing diagram
- Differences and similarities between detection circuits, filter circuits, frequency selection circuits, threshold comparison circuits, and bandpass circuits
- When designing PCB, how to consider electromagnetic compatibility EMC/EMI, specifically...
- How to measure the PWM generated by msp430f149 with an oscilloscope
- EEWORLD University ---- Signal Processing on MSP430 16-bit MCU