本帖最后由 wangjinkui 于 2017-10-30 22:29 编辑
stm32F4 使用串口DMA,空闲中断接收不定长的数据,单步调试的时候没有问题,全速运行时就出错了,出错的原因是进入中断后只收到几个数据,我想是不是时序的问题,改不过来了,请问有没有了解这是什么情况的能不能给一下指导,谢谢。相关代码如下:
主函数:
- HAL_UART_Transmit(&huart2,HG1134_stop,6, 0xFFFF); //
- // HAL_UART_Transmit(&huart6,HG1134_stop,6, 0xFFFF); //
- __HAL_UART_DISABLE_IT(&huart3, UART_IT_IDLE); //
- __HAL_UART_ENABLE_IT(&huart2, UART_IT_IDLE); //
- HAL_UART_Receive_DMA(&huart2, Usart2Type.usartDMA_rxBuf, RECEIVELEN); //
- while(Eph_ready == 0)
- {
- HAL_UART_Transmit(&huart2,HG1134_stop,6, 0xFFFF); //
- HAL_Delay(1);
- HAL_UART_Transmit(&huart2,HG1134_ephout,8, 0xFFFF); //
- HAL_UART_Transmit(&huart6,HG1134_ephout,8, 0xFFFF); //
- HAL_Delay(300);
- huart2.hdmarx->State = HAL_DMA_STATE_READY;
- HAL_UART_Receive_DMA(&huart2,Usart2Type.usartDMA_rxBuf,RECEIVELEN);
- }
- __HAL_UART_DISABLE_IT(&huart2, UART_IT_IDLE); //
- HAL_UART_DMAStop(&huart2); //
- HAL_UART_Transmit(&huart3,HG1134_close,7, 0xFFFF); //
- __HAL_UART_ENABLE_IT(&huart3, UART_IT_IDLE); //
- HAL_UART_Receive_DMA(&huart3, Usart3Type.usartDMA_rxBuf, RECEIVELEN);
复制代码 中断函数
:
- void Usart2Receive_IDLE(UART_HandleTypeDef *huart)
- {
- uint32_t temp;
- if((__HAL_UART_GET_FLAG(huart,UART_FLAG_IDLE) != RESET))
- {
- __HAL_UART_CLEAR_IDLEFLAG(huart);
- HAL_UART_DMAStop(huart);
- temp = __HAL_DMA_GET_COUNTER(huart->hdmarx);
- Usart2Type.rx_len = RECEIVELEN - temp;
- if(Usart2Type.usartDMA_rxBuf[0] == 0x90&&Usart2Type.usartDMA_rxBuf[1] ==0xEB&&Usart2Type.usartDMA_rxBuf[4] ==0x45)
- {
- Eph_ready = 1;
- Eph_len = Usart2Type.rx_len;
- memcpy(Eph_buf,Usart2Type.usartDMA_rxBuf,Usart2Type.rx_len);
- }
- }
- }
复制代码
|
评分
查看全部评分
评分
查看全部评分
评分
查看全部评分