Error in USART Module with Baudrate Constants

General discussion relating to the library modules supplied with the compiler

Moderators: David Barker, Jerry Messina

Post Reply
Rickado
Registered User
Registered User
Posts: 17
Joined: Tue Apr 28, 2009 9:43 pm
Location: Dunedin, New Zealand

Error in USART Module with Baudrate Constants

Post by Rickado » Thu Dec 09, 2010 8:23 pm

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

Jerry Messina
Swordfish Developer
Posts: 1469
Joined: Fri Jan 30, 2009 6:27 pm
Location: US

Post by Jerry Messina » Fri Dec 10, 2010 11:56 am

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.

Post Reply