Page 1 of 1

Error in USART Module with Baudrate Constants

Posted: Thu Dec 09, 2010 8:23 pm
by Rickado
From DataSheets
Baudrate = Fosc/(Fmult *(SPBRGRegister + 1))

therefore
SPBRGRegister + 1 =Fosc/(Fmult * Baudrate)

therefore
SPBRGRegister = (Fosc/(Fmult * Baudrate)) - 1

So
br300 to br115200 which goes into SPBRGRegister should be

br300 = Fosc/(Fmult * 300) - 1 + 0.5, // + 0.5 for rounding

ie no + 1 on the baudrates

Posted: Fri Dec 10, 2010 11:56 am
by Jerry Messina
I could be completely wrong on this, but with the "+1" being in the divisor, it's not going to have much of an effect on the outcome considering the size of the numbers involved.

I don't have the patience to check, but perhaps there are certain combinations where it helps produce a "better" result, just like adding the 0.5 to round the result up does, I suppose.

But you're right...it doesn't match the datasheet calculation 100%. Whether it's a mistake or not, I couldn't tell you.