I need to be able to set the baud rate and it works in an unusual way. I have to set the USARTDIV and it needs floating point accuracy.
USARTDIV = Fck / (16 * baud) which quite often gives a floating point outcome. See some examples from datasheet

- uart.JPG (51.56 KiB) Viewed 268 times
USARTDIIV = Fclk/baud;
will do.
Does this mean the top 12 bits are _mantissa = 234 and the bottom 4 bits are _fraction = 375/16 = 23.4375 so round to 23 ????
36Mhz/115.2kbps = 312.5 -> usartdiv = 312.
the chart tells you to code 19.5 -> 19 * 16 + 0.5*16 = 304 + 8 = 312. you may also consider implement rounding here.
the key here is that the fraction is the lowest 4 bits coded in 1/16th and the mantissa the upper bits.
if not, you will need to play around with some integer math: on that the msp432 has some of the most painful baud rate calculations I have ever seen.
36Mhz / 9600 = 3750
if I look at your method 3750 = 0b 0000 1110 1010 0110
if I look at the data sheet it gives 234.375 which is 234 in mantissa with fraction being 375/1000 expressed in 1/16th’s
mantissa= 234 << 4 = 0b 0000 1110 1010 0000
fraction = 375/(1000/16) = 6 = 0b 0110
doing mantissa | fraction = 0b 0000 1110 1010 0110
It seems just doing fck/baud and rounding is a quick cut to the same answer. Not sure why the datasheet gives us the long way around
@stevestrong
thanKs for the link. I looked at the code and understand how it works. It does what the data sheet explains but as dannf has posted there is a simpler way to do it.
Thanks everyone that has helped me out. I think that I understand it now ![]()
if you think the approach in the datasheet is nuts, take a look at how SPL did it – it is insane.
it is part of the free benefits of using ST parts,
things like that aren’t unique to this particular module / part.
You do not need floating point, imho.



