2014-06-26 08:01 AM
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.2014-06-26 08:08 AM
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.
2014-06-26 11:57 PM
And what would happen during a reception ?
2014-06-27 12:11 AM
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.
2014-06-27 12:14 AM
OK thank you guys !
2014-06-27 12:18 AM
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.