AnsweredAssumed Answered

Change Uart baud rate on the fly with cube?

Question asked by nibbles on Sep 18, 2017
Latest reply on Sep 19, 2017 by nibbles

I see that this has been asked a few times with no real resolution or workaround, so I'll ask again please?

 

I have USART3 configured at 9600 Baud. I test this with a terminal program also set at 9600 and it works fine.

I then execute the following 2 line to try and change the baud rate on the fly

 

MX_USART3_UART_DeInit();
MX_USART3_UART_Init_Custom(19200); 

 

and then set my terminal program to 19200 baud but uart on processor just stops receiving....

 

MX_USART3_UART_Init_Custom is a copy the standard MX_USART3_UART function with a configurable baud rate

:-

void MX_USART3_UART_Init_Custom(unsigned int baud)
{

huart3.Instance = USART3;
huart3.Init.BaudRate = baud;
huart3.Init.WordLength = UART_WORDLENGTH_8B;
huart3.Init.StopBits = UART_STOPBITS_1;
huart3.Init.Parity = UART_PARITY_NONE;
huart3.Init.Mode = UART_MODE_TX_RX;
huart3.Init.HwFlowCtl = UART_HWCONTROL_NONE;
huart3.Init.OverSampling = UART_OVERSAMPLING_16;
huart3.Init.OneBitSampling = UART_ONE_BIT_SAMPLE_DISABLE;
huart3.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_NO_INIT;
if (HAL_UART_Init(&huart3) != HAL_OK)
{
_Error_Handler(__FILE__, __LINE__);
}
}

 

 

Any ideas?

Outcomes