STM32L051C8T6HALDMAIDLE串口不定长接收遇到的问题
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
STM32L051C8T6HALDMAIDLE串⼝不定长接收遇到的问题DMA中断,串⼝不定长接收,⽆法连续发送第⼆个printf
写2个printf只能发送第⼀个,第⼆个需要延时5S左右才能发送。
⽆法把串⼝状态置为READY
初始化的时候 Main.c
要使能串⼝中断 DMA
``
HAL_NVIC_EnableIRQ(DMA1_Channel2_3_IRQn);
HAL_UART_Receive_DMA(&huart1, artDMA_rxBuf, USART1_MAX_RECV_LEN);
__HAL_UART_ENABLE_IT(&huart1, UART_IT_IDLE);
``
HAL 串⼝库.c
添加串⼝发送完毕状态
/**
@brief DMA UART transmit process complete callback.
@param hdma DMA handle.
@retval None
*/
static void UART_DMATransmitCplt(DMA_HandleTypeDef *hdma)
{
UART_HandleTypeDef *huart = (UART_HandleTypeDef *)(hdma->Parent);
/* DMA Normal mode */
if (HAL_IS_BIT_CLR(hdma->Instance->CCR, DMA_CCR_CIRC))
{
huart->TxXferCount = 0U;
/* Disable the DMA transfer for transmit request by resetting the DMAT bit
in the UART CR3 register */
CLEAR_BIT(huart->Instance->CR3, USART_CR3_DMAT);
/* Enable the UART Transmit Complete Interrupt */
SET_BIT(huart->Instance->CR1, USART_CR1_TCIE);
/* Check if a transmit process is ongoing or not */
if(huart->gState == HAL_UART_STATE_BUSY_TX_RX)
{
huart->gState = HAL_UART_STATE_BUSY_RX;
}
else
{
huart->gState = HAL_UART_STATE_READY;
}
}
/* DMA Circular mode */
else
{
if (USE_HAL_UART_REGISTER_CALLBACKS == 1)
/*Call registered Tx complete callback*/
huart->TxCpltCallback(huart);
else
/*Call legacy weak Tx complete callback*/
HAL_UART_TxCpltCallback(huart);
endif /* USE_HAL_UART_REGISTER_CALLBACKS */
}
}。