Designer III Blog (home)
New Comments Designer III Blog RSS Feed

Designer III Blog January Archive

Favorite Posts:
, :




FFF5D6,FFF5D6,FFF5D6,FFE699
Other Resources
FFF5D6,FFF5D6,FFF5D6,FFE699
Tags

Blog Roll:


interger truncation Designer III Blog; January, 2009 Archive; Designer III Blog

Why is my AVR baud rate wrong?

By Bob Paddock at 01/11/09 20:13

Recent AVR-LibC FAQ submission of mine:

Why is my AVR baud rate wrong?

Some AVR datasheets give the following formula for calculating baud rates:

(F_CPU/(UART_BAUD_RATE*16L)-1)

Unfortunately that formula does not work with all combinations of clock speeds and baud rates due to integer truncation during the division operator.

When doing integer division it is usually better to round to the nearest integer, rather than to the lowest. To do this add 0.5 (i.e. half the value of the denominator) to the numerator before the division, resulting in the formula:

((F_CPU + UART_BAUD_RATE * 8L) / (UART_BAUD_RATE * 16L) - 1)

 


Tags: avr baud rate • interger truncation • round to nearest integer • avr libc •
0 Comments. - Permalink


interger truncation Archives: • January, 2009



* com * top 100 * 10 * 2054 * Blog * Espanol *

Have you added a link to us from your website? (2054):

  • <a href="http://blog.designer-iii.com">Designer III Blog</a>
interger truncation Designer III Blog; January, 2009 Archive; Designer III Blog

Web site copyright (c) 2007-2010 GLR Sales LLC.




(rozwqizwpwzpp)

Privacy & DMCA Policy -- Those who twitter us!
interger truncation Designer III Blog January Archive