AVR-GCC Libraries
uart.h
Go to the documentation of this file.
1 #ifndef UART_H
2 #define UART_H
3 /************************************************************************
4 Title: Interrupt UART library with receive/transmit circular buffers
5 Author: Peter Fleury <pfleury@gmx.ch> http://tinyurl.com/peterfleury
6 File: $Id: uart.h,v 1.13 2015/01/11 13:53:25 peter Exp $
7 Software: AVR-GCC 4.x, AVR Libc 1.4 or higher
8 Hardware: any AVR with built-in UART/USART
9 Usage: see Doxygen manual
10 
11 LICENSE:
12  Copyright (C) 2015 Peter Fleury, GNU General Public License Version 3
13 
14  This program is free software; you can redistribute it and/or modify
15  it under the terms of the GNU General Public License as published by
16  the Free Software Foundation; either version 3 of the License, or
17  any later version.
18 
19  This program is distributed in the hope that it will be useful,
20  but WITHOUT ANY WARRANTY; without even the implied warranty of
21  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22  GNU General Public License for more details.
23 
24 ************************************************************************/
25 
50 #include <avr/pgmspace.h>
51 
52 #if (__GNUC__ * 100 + __GNUC_MINOR__) < 405
53 #error "This library requires AVR-GCC 4.5 or later, update to newer AVR-GCC compiler !"
54 #endif
55 
56 
60 /*
61 ** constants and macros
62 */
63 
64 
69 #define UART_BAUD_SELECT(baudRate,xtalCpu) (((xtalCpu) + 8UL * (baudRate)) / (16UL * (baudRate)) -1UL)
70 
75 #define UART_BAUD_SELECT_DOUBLE_SPEED(baudRate,xtalCpu) ( ((((xtalCpu) + 4UL * (baudRate)) / (8UL * (baudRate)) -1UL)) | 0x8000)
76 
82 #ifndef UART_RX_BUFFER_SIZE
83 #define UART_RX_BUFFER_SIZE 32
84 #endif
85 
91 #ifndef UART_TX_BUFFER_SIZE
92 #define UART_TX_BUFFER_SIZE 32
93 #endif
94 
95 /* test if the size of the circular buffers fits into SRAM */
96 #if ( (UART_RX_BUFFER_SIZE+UART_TX_BUFFER_SIZE) >= (RAMEND-0x60 ) )
97 #error "size of UART_RX_BUFFER_SIZE + UART_TX_BUFFER_SIZE larger than size of SRAM"
98 #endif
99 
100 /*
101 ** high byte error return code of uart_getc()
102 */
103 #define UART_FRAME_ERROR 0x1000
104 #define UART_OVERRUN_ERROR 0x0800
105 #define UART_PARITY_ERROR 0x0400
106 #define UART_BUFFER_OVERFLOW 0x0200
107 #define UART_NO_DATA 0x0100
110 /*
111 ** function prototypes
112 */
113 
119 extern void uart_init(unsigned int baudrate);
120 
121 
146 extern unsigned int uart_getc(void);
147 
148 
154 extern void uart_putc(unsigned char data);
155 
156 
167 extern void uart_puts(const char *s );
168 
169 
181 extern void uart_puts_p(const char *s );
182 
186 #define uart_puts_P(__s) uart_puts_p(PSTR(__s))
187 
188 
189 
191 extern void uart1_init(unsigned int baudrate);
193 extern unsigned int uart1_getc(void);
195 extern void uart1_putc(unsigned char data);
197 extern void uart1_puts(const char *s );
199 extern void uart1_puts_p(const char *s );
201 #define uart1_puts_P(__s) uart1_puts_p(PSTR(__s))
202 
206 #endif // UART_H
207 
void uart1_puts_p(const char *s)
Put string from program memory to ringbuffer for transmitting via USART1 (only available on selected ...
void uart1_putc(unsigned char data)
Put byte to ringbuffer for transmitting via USART1 (only available on selected ATmega) ...
void uart_puts(const char *s)
Put string to ringbuffer for transmitting via UART.
unsigned int uart_getc(void)
Get received byte from ringbuffer.
void uart1_init(unsigned int baudrate)
Initialize USART1 (only available on selected ATmegas)
void uart_puts_p(const char *s)
Put string from program memory to ringbuffer for transmitting via UART.
void uart_init(unsigned int baudrate)
Initialize UART and set baudrate.
unsigned int uart1_getc(void)
Get received byte of USART1 from ringbuffer. (only available on selected ATmega)
void uart_putc(unsigned char data)
Put byte to ringbuffer for transmitting via UART.
void uart1_puts(const char *s)
Put string to ringbuffer for transmitting via USART1 (only available on selected ATmega) ...