AVR C Runtime Library - Patches: patch #5343, Add a util/setbaud.h...
You are not allowed to post comments on this tracker with your current authentication level.
patch #5343: Add a util/setbaud.h "helper" file
Submitter: | Cliff Lawson <clawson> | ||
Submitted: | Tue 29 Aug 2006 09:13:30 AM UTC | ||
Category: | None | Priority: | 5 - Normal |
Status: | Done | Privacy: | Public |
Assigned to: | joerg_wunsch | Open/Closed: | Closed |
Thu 31 Aug 2006 04:25:34 PM UTC, comment #3: |
Carlos Lamas <carloslamas> |
Wed 30 Aug 2006 02:16:16 PM UTC, comment #2: Carlos,
|
Cliff Lawson <clawson> |
Wed 30 Aug 2006 01:46:27 PM UTC, comment #1: With the same philosophy of the last submission I've modified the static approach of the header to let the preprocessor calculate the appropriated values without limiting the processor or baud rate frequencies. Maybe this is more versatile.
|
Carlos Lamas <carloslamas> |
Tue 29 Aug 2006 09:13:30 AM UTC, original submission:
This is a header file to aid the setting of UBRR for an AVR UART. Rather than calculating the UBRR value to use based on F_CPU and BAUD (which is prone to rounding errors) it uses a look up table for popular F_CPU and BAUD values. A further advantage is that ONLY baud rates that can operate with less than +/-2% error are offered. Attempts to use an out of range baud rate will just produce a #error. The file also know when a selected baud rate can only be achieved using U2X=1 mode and in this case it defines a USE_2X value so that code to set U2X=1 mode can be wrapped in a #ifdef USE_2X/#endif |
Cliff Lawson <clawson> |
Depends on the following items: None found
Items that depend on this one: None found
There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.
Follow 7 latest changes.
Date | Changed by | Updated Field | Previous Value | => | Replaced by |
---|---|---|---|---|---|
2007-10-28 | joerg_wunsch | Status | In Progress | Done | |
Open/Closed | Open | Closed | |||
2007-10-28 | joerg_wunsch | Status | None | In Progress | |
Assigned to | None | joerg_wunsch | |||
2006-08-31 | carloslamas | Attached File | - | Added setbaud.h, #10659 | |
2006-08-30 | carloslamas | Attached File | - | Added setbaud.h, #10638 | |
2006-08-29 | clawson | Attached File | - | Added setbaud.h, #10626 |
Powered by Savane 3.13-758e.
Corresponding source code
Hello,
There were overflow problems with baud rates lower than 32768 in C expressions. I couldn't see the problem before because my F_CPU and BAUD were defined long. This is solved in version 1.3 submitted by tacking UL at the end of the constants involved to force the compiler to use long type arithmetics. cpp expressions (#if's) are supposed to operate in 64 bit precision and they shouldn't overflow for reasonable frequency and baud rate values.
The rounding errors were issued previously and they should not give different results to hand calculated.
UBRR values delivered had the same error tolerance, 2% default. Obviously when there was no overflow errors.
U2X=0 was always used when possible.
Anyway, I can't see advantages in using a "short" lookup table for this case of so many possible F_CPU/BAUD combinations.
Carlos.