2 This file is part of the AVR-uart_ni.
3 Copyright (C) 2009 Daniel Otte (daniel.otte@rub.de)
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
19 /* #include <util/setbaud.h> */
20 /* we use a modifyed version of util/setbaud where the UL suffix is removed
21 * since the preprocessor can not handle that.
25 # error "uart_i requires F_CPU to be defined"
29 # error "uart_i requires UART0_BAUD_RATE to be defined"
33 # error "F_CPU must be a constant value"
37 # error "UART0_BAUD_RATE must be a constant value"
42 /* Baud rate tolerance is 2 % unless previously defined */
47 #define UBRR_VALUE (((F_CPU) + 8 * (BAUD)) / (16 * (BAUD)) -1)
50 (16 * ((UBRR_VALUE) + 1)) * (100 * (BAUD) + (BAUD) * (BAUD_TOL))
52 #elif 100 * (F_CPU) < \
53 (16 * ((UBRR_VALUE) + 1)) * (100 * (BAUD) - (BAUD) * (BAUD_TOL))
60 /* U2X required, recalculate */
62 #define UBRR_VALUE (((F_CPU) + 4 * (BAUD)) / (8 * (BAUD)) -1)
65 (8 * ((UBRR_VALUE) + 1)) * (100 * (BAUD) + (BAUD) * (BAUD_TOL))
66 # warning "Baud rate achieved is higher than allowed"
70 (8 * ((UBRR_VALUE) + 1)) * (100 * (BAUD) - (BAUD) * (BAUD_TOL))
71 # warning "Baud rate achieved is lower than allowed"
77 # define UBRRL_VALUE ((UBRR_VALUE) & 0xff)
78 # define UBRRH_VALUE ((UBRR_VALUE) >> 8)