Can someone tell me the procedure to change the baud rate on the USART once it has already been initialized? I have a module that I communicate with using USART2 and I need to be able to change the baud rate on the module then change the USART baud rate on the STM32. I am using a the rxne interrupt to receieve data. This is my code to try and change the baud rate.
void UART_ChangeBaud(u32 UartSpeed)
{
USART_InitTypeDef USART_InitStructure;
GPIO_InitTypeDef GPIO_InitStructure;
/* DISABLE USART2 Receive and Transmit interrupts */
USART_ITConfig(USART2, USART_IT_RXNE, DISABLE);
USART_InitStructure.USART_BaudRate = UartSpeed;//9600;//115200;
USART_InitStructure.USART_WordLength = USART_WordLength_8b;
USART_InitStructure.USART_StopBits = USART_StopBits_1;
USART_InitStructure.USART_Parity = USART_Parity_No ;
USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_RTS_CTS;
USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
USART_Init(USART2, &USART_InitStructure);
USART_ClearFlag(USART2, USART_FLAG_RXNE);
USART_ClearITPendingBit(USART2, USART_IT_RXNE);
/* Enable USART2 Receive and Transmit interrupts */
USART_ITConfig(USART2, USART_IT_RXNE, ENABLE);
//USART_ITConfig(USART2, USART_IT_TXE, ENABLE);
/* Enable the USART2 */
USART_Cmd(USART2, ENABLE);
return;
}
Is my procedure incorrect? Once I try to change the baud rate I can't receive anything from the module.