cancel
Showing results for 
Search instead for 
Did you mean: 

Update Usart baud rate register during communication

nicolas23
Associate II
Posted on June 26, 2014 at 17:01

Hello,

I would like to know what happens if I modify the USART baud rate register value very little (+-3%) during a communication. Is it safe or is it essential to stop the communication before updating the BRR value even if the new value is really close to the old one ?

I hope that my questions are understandable.

Thank you.
5 REPLIES 5
Posted on June 26, 2014 at 17:08

You'd want to wait unit the TC bit asserts before changing the baud rate or sending new characters, otherwise you're likely to corrupt data on the wire.

Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..
nicolas23
Associate II
Posted on June 27, 2014 at 08:57

And what would happen during a reception ?

John F.
Senior
Posted on June 27, 2014 at 09:11

It depends on the exact hardware implementation of the baud rate generator. For the STM32F4 for example each bit period is sampled 8 or 16 times (programmable) and a voting system decides the bit state. Look up the details for your device in the reference manual and work out the timings. Worst case, you might miss one byte I think.

nicolas23
Associate II
Posted on June 27, 2014 at 09:14

OK thank you guys !

Posted on June 27, 2014 at 09:18

The crux of the problem is you have no real visibility into the internals of the usart, or the state of the counters/prescalers etc, or how it adjusts to the bit centre of received data. You can't really control when you are writing into the registers with respect to these things, and the behaviour therefore is going to be somewhat indeterminate. A gate level description of the implementation is unlikely to be forth coming.

On the receive side your most opportune time would be as RXNE is raised, marking that you are currently in whatever inter-symbol gap you have, ie stop bit(s) of last character vs start bit of next/current character. TXE will transition low-to-high at roughly the point it's going to output the start bit of the character it just moved from the holding register to the shift register.

You'll have to experiment. Put a scope or logic analyzer on the system and review what it does. Have GPIO reflect the state of RXNE, TXE either directly, or toggling as interesting transition points.

If I understood a little more about why this was all necessary, I could perhaps make some other suggestions.
Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..