Serial port to receive variable length data program (for no idle interrupt SCM), uses a timer to determine whether the receiving end, test procedures send more than 50ms interval will not appear on the stick pack phenomenon STM32F4 explorers, 20ms occasionally stick pack phenomenon .
typedef struct { uint8_t Rec_Flag; uint8_t Process; uint8_t timeout;/* 单位ms */ uint8_t Rx_Length; uint8_t Tx_Buf[64]; uint8_t Rx_Buf[64]; }USART_RTx_TypeDef; extern USART_RTx_TypeDef USART2_RTx; void USART2_IRQHandler(void) { IF(LL_USART_IsActiveFlag_RXNE(USART2) != RESET) { USART2_RTx.Rx_Buf[USART2_RTx.Rx_Length++]=USART2->DR; switch(USART2_RTx.Process) { case 0: USART2_RTx.Timeout=3; USART2_RTx.Process=1; LL_TIM_EnableCounter(TIM1); break; case 1: USART2_RTx.Timeout=3; break; default: USART2_RTx.Timeout=0; USART2_RTx.Process=0; LL_TIM_DisableCounter(TIM1); break; } } } void TIM1_UP_TIM10_IRQHandler(void) { /* USER CODE BEGIN TIM1_UP_TIM10_IRQn 0 */ if(LL_TIM_IsActiveFlag_UPDATE(TIM1) != RESET) { LL_TIM_CleaRFlag_UPDATE(TIM1); USART2_RTx.Timeout--; if(USART2_RTx.Timeout == 0) { USART2_RTx.Rec_Flag=1;/* 接收完成标志 */ LL_TIM_DisableCounter(TIM1); USART2_RTx.Process=0; } } }
Finally, still provide some information to you, I hope in a way to help everyone
(Stm32 serial application)
http://www.makeru.com.cn/live/1392_1164.html?s=45051
Based on STM32 explain serial operation
http://www.makeru.com.cn/live/1758_490.html?s=45051