Once the transfer has completed, this register can either stay at zero (when the stream is in
normal mode) or be reloaded automatically with the previously programmed value in the
following cases:
– when the stream is configured in Circular mode.
– when the stream is enabled again by setting EN bit to '1'
If the value of this register is zero, no transaction can be served even if the stream is
enabled.
HAL_UART_Receive_DMA(&huart1, RX_DATA, RX_DATA_NUM);
__HAL_DMA_DISABLE_IT(huart1.hdmarx, DMA_IT_TC | DMA_IT_HT | DMA_IT_TE);//关闭DMA 错误 传输一半 全部完成 中断
__HAL_UART_ENABLE_IT(&huart1, UART_IT_IDLE);//使能 串口 空闲中断
HAL_NVIC_SetPriority(USART1_IRQn, 1, 0);
HAL_NVIC_EnableIRQ(USART1_IRQn); //使能中断
void USART1_IRQHandler(void)
{
if((__HAL_DMA_GET_COUNTER(huart1.hdmarx) + RX_DATA[3]) == (RX_DATA_NUM - 6))
{
Flag_RX = 1;
}
__HAL_UART_CLEAR_IT(&huart1, UART_CLEAR_IDLEF);
__HAL_DMA_DISABLE(huart1.hdmarx);
huart1.hdmarx->Instance->CNDTR = RX_DATA_NUM;
__HAL_DMA_ENABLE(huart1.hdmarx); //DMA接收数据 必须在 DMA 禁止 时 重新写入
}
你把 HAL_UART_DMAStop(huart); 一句去掉就应该没事了!具体见手册
Once the transfer has completed, this register can either stay at zero (when the stream is in
normal mode) or be reloaded automatically with the previously programmed value in the
following cases:
– when the stream is configured in Circular mode.
– when the stream is enabled again by setting EN bit to '1'
If the value of this register is zero, no transaction can be served even if the stream is
enabled.
再一点HAL_UART_DMAStop会把 发送和接收都给停止,这就 导致 异步传输没有意义了。。
我觉得大家把这个路走歪了点,
__HAL_DMA_DISABLE_IT(huart1.hdmarx, DMA_IT_TC | DMA_IT_HT | DMA_IT_TE);//关闭DMA 错误 传输一半 全部完成 中断
这里如果将DMA配置成一锤子买卖,肯定会丢东西。
--------------------------------------------------------------------------------------------------------------------------------------------------------------
不如将DMA配置成Circular模式,不要停止DMA,另外开启
DMA缓冲区可以设置为256字节,这样缓冲区读指针可以采用基地址+一个UINT8偏移实现,UINT8自动溢出循环256。