我在 DMA 模式下使用 UART4。但是,一旦我在 RX 模式下初始化 UART,我就会收到一个调用 HAL_UART_ErrorCallback Error _Handler 的帧错误,它会暂停程序。下面是我的初始化代码。
- /* UART4 init function */
- void UART4_Init(void)
- {
- UartReady = false;
- huart4.Instance = UART4;
- huart4.Init.BaudRate = 115200;
- huart4.Init.WordLength = UART_WORDLENGTH_8B;
- huart4.Init.StopBits = UART_STOPBITS_1;
- huart4.Init.Parity = UART_PARITY_NONE;
- huart4.Init.Mode = UART_MODE_TX_RX;
- huart4.Init.HwFlowCtl = UART_HWCONTROL_NONE;
- huart4.Init.OverSampling = UART_OVERSAMPLING_16;
- huart4.Init.OneBitSampling = UART_ONE_BIT_SAMPLE_DISABLE;
- huart4.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_NO_INIT;
- if (HAL_UART_Init(&huart4) != HAL_OK)
- {
- Error_Handler();
- }
- UartReady = false;
- GPIO_Set_RS485_TXEN(0);
- HAL_UART_Receive_DMA( &huart4, UART_RX_Buffer, cmdLen);
- }
错误发生在最后一行 (HAL_UART_Receive_DMA().
如何防止此错误?
指导赞赏....