/var/www/restricted/ssh/stm32/www/stm32circle/ STM CircleOS forum / Change USART Baud Rate on the fly?

Username:     
Password:     
             

Forum

# 1   2009-02-18 23:51:31 Change USART Baud Rate on the fly?

ProjectPat
New member
Registered: 2008-08-22
Posts: 2

Change USART Baud Rate on the fly?

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.

Offline

 

# 2   2009-02-19 07:49:32 Change USART Baud Rate on the fly?

Francis
Administrator
From: France-Grenoble
Registered: 2007-07-09
Posts: 890

Re: Change USART Baud Rate on the fly?

Do you manage properly the Hw control ? (USART_HardwareFlowControl_RTS_CTS).

Offline

 

# 3   2009-02-20 14:20:54 Change USART Baud Rate on the fly?

ProjectPat
New member
Registered: 2008-08-22
Posts: 2

Re: Change USART Baud Rate on the fly?

What should be managed? Doesn't the hardware take care of it? Should I try and flush the receive buffer?

Offline

 

# 4   2009-02-20 16:12:14 Change USART Baud Rate on the fly?

Francis
Administrator
From: France-Grenoble
Registered: 2007-07-09
Posts: 890

Re: Change USART Baud Rate on the fly?

I just see that you selected 'USART_HardwareFlowControl_RTS_CTS'. On the other side (hyper-terminal,...) you need to select the right mode (and to connect these signals too).

Offline

 

Board footer