cancel
Showing results for 
Search instead for 
Did you mean: 

Change the USART Baudrate !

leventeyigel52
Associate II
Posted on July 25, 2012 at 20:37

Hello I want to change the USART baudrate in some conditions but i couldn't do this.

switch( bdstate)

          {

            case 0 :

              DownloadUsartConfig(9600);

              break;

            case 1 :

             DownloadUsartConfig(19200);

              break;

            case 2 :

              DownloadUsartConfig(38400);

              break;

            case 3 :

              DownloadUsartConfig(57600);

              break;

            case 4 :

              DownloadUsartConfig(115200);

              break;

            default:

              break ; 

          

          

          }

the function is :

void DownloadUsartConfig(uint32_t baudrate)

{

  USART_InitStructure.USART_BaudRate = baudrate;

  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_None;

  USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;

  

  /* Configure USART2 */

  USART_Init(DL_USART, &USART_InitStructure);

  

  USART_ITConfig(DL_USART, USART_IT_RXNE, ENABLE);

  /* Enable the USART2 */

  USART_Cmd(DL_USART, ENABLE);

}

it doesn't work 

How can do about the this problem ? Where doing i  make  mistake ?
6 REPLIES 6
Posted on July 25, 2012 at 20:52

I would think just doing the USART_Init() portion would be sufficient, I swear I've done this before when downshifting the CORE/APB clocks.

What you'd want to be sure of is that you aren't actively transmitting, ie wait for TC and TXE, so you don't change mid symbol.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
leventeyigel52
Associate II
Posted on July 25, 2012 at 21:20

I understood that 

case 0 :

USART_InitStructure.USART_BaudRate = 9600;

USART_Init(DL_USART, &USART_InitStructure);

break;

case 1:

USART_InitStructure.USART_BaudRate = 19200;

USART_Init(DL_USART, &USART_InitStructure);

break;

...

...

Like it ?

Posted on July 26, 2012 at 20:14

''it doesn't work''

That is not a useful description of the problem!

Do you mean it sets the wrong baud rate? Or sets it, but won't change it? Or the UART doesn't work at all? Or what??

What debugging have you done to locate the problem?

Have you started with a basic, working example on DevKit or Discovery Board or similar?

http://www.catb.org/~esr/faqs/smart-questions.html

leventeyigel52
Associate II
Posted on July 26, 2012 at 20:54

Everything is ok

At the first the baudrate must be 9600 and than it will be change in some conditions.

when i changed the bd on the source code i saw the signals like noise ?

Scope can't decode this signals .. 

Posted on July 27, 2012 at 00:40

''Everything is ok''

You mean the problem is now solved?
leventeyigel52
Associate II
Posted on July 27, 2012 at 03:08

No I'm trying still

Only problem is changing baudrate. usart is working