Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Suggestion to solve system clock issue #2

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

simonklee
Copy link
Contributor

Since the serial.h code is only working with a 16MHz clock I've been using this hack since I run my clock system clock at different speeds. The following suggestion uses a small macro which takes the F_CPU value defined in Hz and calculates the baud rate based on that. It's not very nice, but it works as far as I know.

The formula is:

baud value = (((F_CPU / (USART_BAUDRATE * 16UL))) - 1) 

see http://www.avrfreaks.net/index.php?name=PNphpBB2&file=viewtopic&t=45341 for more info regarding this, but you probably know it already.

The "bad" with this commit is that you end up being dependent on having the F_CPU value set(either in Makefile or before importing the serial.h code).

@simonklee
Copy link
Contributor Author

I just realized my attached patch is somewhat wrong. Since you are using the double speed operation in asynchronous mode (by setting the U2X0 bit UCSR0A). Setting that bit will reduce the divisor of the baud rate divider from 16 to 8, so the formula should multiply by 8 instead.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant