stm32F429 UART7 idle 出现一个问题,现象:设置IDLE中断,在接收数据时,每一个字节都会进IDLE,而且还会进两次。
还用了USART1 USART2 USART3 ,代码设置是一致的,进IDLE很正常。 就这个uart7的IDLE 有问题,很疑惑。
主要代码如下
初始化
```
void MX_UART7_Init(void)
{
/* USER CODE BEGIN UART7_Init 0 */
/* USER CODE END UART7_Init 0 */
LL_USART_InitTypeDef USART_InitStruct = {0};
LL_GPIO_InitTypeDef GPIO_InitStruct = {0};
/* Peripheral clock enable */
LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_UART7);
LL_AHB1_GRP1_EnableClock(LL_AHB1_GRP1_PERIPH_GPIOF);
/**UART7 GPIO Configuration
PF6 ------> UART7_RX
PF7 ------> UART7_TX
*/
GPIO_InitStruct.Pin = UART_422_Backup_RX_Pin|UART_422_Backup_TX_Pin;
GPIO_InitStruct.Mode = LL_GPIO_MODE_ALTERNATE;
GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_VERY_HIGH;
GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL;
GPIO_InitStruct.Pull = LL_GPIO_PULL_UP;
GPIO_InitStruct.Alternate = LL_GPIO_AF_8;
LL_GPIO_Init(GPIOF, &GPIO_InitStruct);
/* UART7 interrupt Init */
NVIC_SetPriority(UART7_IRQn, NVIC_EncodePriority(NVIC_GetPriorityGrouping(),1, 0));
NVIC_EnableIRQ(UART7_IRQn);
/* USER CODE BEGIN UART7_Init 1 */
/* USER CODE END UART7_Init 1 */
USART_InitStruct.BaudRate = 115200;
USART_InitStruct.DataWidth = LL_USART_DATAWIDTH_8B;
USART_InitStruct.StopBits = LL_USART_STOPBITS_1;
USART_InitStruct.Parity = LL_USART_PARITY_NONE;
USART_InitStruct.TransferDirection = LL_USART_DIRECTION_TX_RX;
USART_InitStruct.HardwareFlowControl = LL_USART_HWCONTROL_NONE;
USART_InitStruct.OverSampling = LL_USART_OVERSAMPLING_16;
LL_USART_Init(UART7, &USART_InitStruct);
LL_USART_ConfigAsyncMode(UART7);
LL_USART_Enable(UART7);
/* USER CODE BEGIN UART7_Init 2 */
LL_USART_EnableIT_IDLE(UART7);
LL_USART_EnableIT_RXNE(UART7);
/* USER CODE END UART7_Init 2 */
}
```
中断部分处理如下,已经都屏蔽了中断内部数据的复制了。
- void UART7_IRQHandler(void)
- {
- /* USER CODE BEGIN UART7_IRQn 0 */
- uint8_t res=res;
- /* USER CODE END UART7_IRQn 0 */
- /* USER CODE BEGIN UART7_IRQn 1 */
- if(LL_USART_IsActiveFlag_RXNE(UART7))
- {
- res = LL_USART_ReceiveData8(UART7);
- }
- if(LL_USART_IsActiveFlag_IDLE(UART7))
- {
- LL_USART_ClearFlag_IDLE(UART7) ;
- }
- /* USER CODE END UART7_IRQn 1 */
- }
复制代码
|