2009-02-19 01:58 AM
Change USART baud rate on the fly?
2011-05-17 04:03 AM
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.2011-05-17 04:03 AM
Hi pdowns;
In your code, you have only disable the receive interrupt, and the transmit interrupt was not disabled: /* DISABLE USART2 Receive and Transmit interrupts */ USART_ITConfig(USART2, USART_IT_RXNE, DISABLE); May this has caused your problem!! B.R. M3allem [ This message was edited by: M3allem on 19-02-2009 10:15 ] [ This message was edited by: M3allem on 19-02-2009 10:16 ]2011-05-17 04:03 AM
I don't think it is that, I only use the RX interrupt. I never enabled the TX intterrupt, I just forgot to edit the comments.