本帖最后由 312011 于 2018-6-15 09:23 编辑 /* * uart1 dma rx idle intrrupt process */ void Addedto_USART1_IRQHandler(void) { if(__HAL_UART_GET_FLAG(&huart1,UART_FLAG_IDLE)!=RESET) //uart1 dma rx idle intrrupt { static uint32_t rxdatanum,temp; __HAL_UART_CLEAR_IDLEFLAG(&huart1); //clear uart1 dma rx idle intrrupt flag temp =huart1.Instance->SR; temp =huart1.Instance->DR; temp=huart1.hdmarx->Instance->NDTR; // CLEAR_BIT(huart1.Instance->CR3, USART_CR3_DMAR); // HAL_DMA_Abort(huart1.hdmarx); __HAL_DMA_DISABLE(huart1.hdmarx); rxdatanum=UART_DMA_RX_SIZE-(__HAL_DMA_GET_COUNTER(huart1.hdmarx)); /* Enable the DMA transfer for the receiver request by setting the DMAR bit in the UART CR3 register */ SET_BIT(huart1.Instance->CR3, USART_CR3_DMAR); /* Enable the Peripheral */ __HAL_DMA_ENABLE(huart1.hdmarx); osMessagePut(Queue_EventUart,(rxdatanum +((uint32_t )EVENT_UART1_RX<<16)),0);//send rx event } } /** * @brief This function handles USART1 global interrupt. */ void USART1_IRQHandler(void) { /* USER CODE BEGIN USART1_IRQn 0 */ /* USER CODE END USART1_IRQn 0 */ HAL_UART_IRQHandler(&huart1); /* USER CODE BEGIN USART1_IRQn 1 */ Addedto_USART1_IRQHandler(); /* USER CODE END USART1_IRQn 1 */ } 为什么这样第一次无法正确接收,需要发两次甚至更多次才能收到上一次的数据?中断停在这个空闲中断处理函数里的sMessagePut函数,发现rxdatanum和temp值不正确,什么原因? |
评分
查看全部评分
评分
查看全部评分