cancel
Showing results for 
Search instead for 
Did you mean: 

UART Framing Error immediately after initializing DMA transfer

Mike Hooper
Senior

I am using the UART4 in DMA mode. But as soon as I initialize the UART in RX mode, I get a framing error that calls the HAL_UART_ErrorCallback Error _Handler which halts the program. Below is my init code.

/* 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);
}

The error occurs at the last line (HAL_UART_Receive_DMA().

How do I prevent this error?

Guidance appreciated....

1 ACCEPTED SOLUTION

Accepted Solutions
Mike Hooper
Senior

Thanks Pavel. It was a hardware problem. works fine now.

View solution in original post

2 REPLIES 2
Pavel A.
Evangelist III

Does framing error occur if you receive without DMA?

If yes, does it persist after 1st byte?

What if you just ignore framing errors in few first bytes?

--pa

Mike Hooper
Senior

Thanks Pavel. It was a hardware problem. works fine now.