How to dynamically change UART baudrate

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
Anonymous
Not applicable

Hi I am using CYBL10573-56LQXI. I have setup an UART with the SCB and I want to change the baudrate when the device is running. I have read the specification explaining how to configure the clock divider to setup the target baudrate, but I do not quite understand.

   

To change the badrate dynamically, I know I need to use an external clock for the UART. By following the example in the spec:

   

// Target buadrate = 115200, over-sampling = 16, HFCLK = 48MHz

   

To set the frequency of the UART clock source: UART Clock = 115200 x 16 = 1.8432MHz  (So I write this in to the Clock source of the UART)

Then Divider = HFCLK / Uart Clock = 48M / 1.8432M = 26
 

   

Then I start the clock and UART by this:

   

UART_Clock_SetDividerValue(26);    // I found the API will subtract the parameter by 1, so I do not subtract myself
UART_Clock_Enable();
UART_1_Start();

   

 

   

However I cannot get it work. I found that if I set the divider to 25:

   

UART_Clock_SetDividerValue(25); 

   

Then it will work. Why?

   

 

   

Also, in this way I can only change the divider number, which cannot let me to change the buadrate dynamically, how can I change the baudrate to for example 19200 when the device is running?

   

 

   

Thank you.

0 Likes
3 Replies
rola_264706
Level 8
Level 8
50 likes received 25 likes received 10 likes received

Please post your code so we can check it.

0 Likes
rola_264706
Level 8
Level 8
50 likes received 25 likes received 10 likes received
0 Likes
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

The SCBs have got an initialization method using a data structure. You could change the appropiate item and re-initialize the UART.

   

 

   

Bob

0 Likes