cancel
Showing results for 
Search instead for 
Did you mean: 

Change USART baud rate on the fly?

pdowns
Associate II
Posted on February 19, 2009 at 10:58

Change USART baud rate on the fly?

3 REPLIES 3
pdowns
Associate II
Posted on May 17, 2011 at 13:03

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.

sofiene
Associate III
Posted on May 17, 2011 at 13:03

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 ]

pdowns
Associate II
Posted on May 17, 2011 at 13:03

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.