AVR-GCC Libraries
|
Interrupt UART library using the built-in UART with transmit and receive circular buffers.
This library can be used to transmit and receive data through the built in UART.
An interrupt is generated when the UART has finished transmitting or receiving a byte. The interrupt handling routines use circular buffers for buffering received and transmitted data.
The UART_RX_BUFFER_SIZE and UART_TX_BUFFER_SIZE constants define the size of the circular buffers in bytes. Note that these constants must be a power of 2. You may need to adapt these constants to your target and your application by adding CDEFS += -DUART_RX_BUFFER_SIZE=nn -DUART_TX_BUFFER_SIZE=nn to your Makefile.
Macros | |
#define | UART_BAUD_SELECT(baudRate, xtalCpu) (((xtalCpu) + 8UL * (baudRate)) / (16UL * (baudRate)) -1UL) |
UART Baudrate Expression. More... | |
#define | UART_BAUD_SELECT_DOUBLE_SPEED(baudRate, xtalCpu) ( ((((xtalCpu) + 4UL * (baudRate)) / (8UL * (baudRate)) -1UL)) | 0x8000) |
UART Baudrate Expression for ATmega double speed mode. More... | |
#define | UART_RX_BUFFER_SIZE 32 |
Size of the circular receive buffer, must be power of 2. More... | |
#define | UART_TX_BUFFER_SIZE 32 |
Size of the circular transmit buffer, must be power of 2. More... | |
#define | UART_FRAME_ERROR 0x1000 |
Framing Error by UART. | |
#define | UART_OVERRUN_ERROR 0x0800 |
Overrun condition by UART. | |
#define | UART_PARITY_ERROR 0x0400 |
Parity Error by UART. | |
#define | UART_BUFFER_OVERFLOW 0x0200 |
receive ringbuffer overflow | |
#define | UART_NO_DATA 0x0100 |
no receive data available | |
#define | uart_puts_P(__s) uart_puts_p(PSTR(__s)) |
Macro to automatically put a string constant into program memory. | |
#define | uart1_puts_P(__s) uart1_puts_p(PSTR(__s)) |
Macro to automatically put a string constant into program memory. | |
Functions | |
void | uart_init (unsigned int baudrate) |
Initialize UART and set baudrate. More... | |
unsigned int | uart_getc (void) |
Get received byte from ringbuffer. More... | |
void | uart_putc (unsigned char data) |
Put byte to ringbuffer for transmitting via UART. More... | |
void | uart_puts (const char *s) |
Put string to ringbuffer for transmitting via UART. More... | |
void | uart_puts_p (const char *s) |
Put string from program memory to ringbuffer for transmitting via UART. More... | |
void | uart1_init (unsigned int baudrate) |
Initialize USART1 (only available on selected ATmegas) More... | |
unsigned int | uart1_getc (void) |
Get received byte of USART1 from ringbuffer. (only available on selected ATmega) More... | |
void | uart1_putc (unsigned char data) |
Put byte to ringbuffer for transmitting via USART1 (only available on selected ATmega) More... | |
void | uart1_puts (const char *s) |
Put string to ringbuffer for transmitting via USART1 (only available on selected ATmega) More... | |
void | uart1_puts_p (const char *s) |
Put string from program memory to ringbuffer for transmitting via USART1 (only available on selected ATmega) More... | |
#define UART_BAUD_SELECT | ( | baudRate, | |
xtalCpu | |||
) | (((xtalCpu) + 8UL * (baudRate)) / (16UL * (baudRate)) -1UL) |
UART Baudrate Expression.
xtalCpu | system clock in Mhz, e.g. 4000000UL for 4Mhz |
baudRate | baudrate in bps, e.g. 1200, 2400, 9600 |
#define UART_BAUD_SELECT_DOUBLE_SPEED | ( | baudRate, | |
xtalCpu | |||
) | ( ((((xtalCpu) + 4UL * (baudRate)) / (8UL * (baudRate)) -1UL)) | 0x8000) |
UART Baudrate Expression for ATmega double speed mode.
xtalCpu | system clock in Mhz, e.g. 4000000UL for 4Mhz |
baudRate | baudrate in bps, e.g. 1200, 2400, 9600 |
#define UART_RX_BUFFER_SIZE 32 |
Size of the circular receive buffer, must be power of 2.
You may need to adapt this constant to your target and your application by adding CDEFS += -DUART_RX_BUFFER_SIZE=nn to your Makefile.
#define UART_TX_BUFFER_SIZE 32 |
Size of the circular transmit buffer, must be power of 2.
You may need to adapt this constant to your target and your application by adding CDEFS += -DUART_TX_BUFFER_SIZE=nn to your Makefile.
void uart_init | ( | unsigned int | baudrate | ) |
Initialize UART and set baudrate.
baudrate | Specify baudrate using macro UART_BAUD_SELECT() |
unsigned int uart_getc | ( | void | ) |
Get received byte from ringbuffer.
Returns in the lower byte the received character and in the higher byte the last receive error. UART_NO_DATA is returned when no data is available.
void uart_putc | ( | unsigned char | data | ) |
Put byte to ringbuffer for transmitting via UART.
data | byte to be transmitted |
void uart_puts | ( | const char * | s | ) |
Put string to ringbuffer for transmitting via UART.
The string is buffered by the uart library in a circular buffer and one character at a time is transmitted to the UART using interrupts. Blocks if it can not write the whole string into the circular buffer.
s | string to be transmitted |
void uart_puts_p | ( | const char * | s | ) |
Put string from program memory to ringbuffer for transmitting via UART.
The string is buffered by the uart library in a circular buffer and one character at a time is transmitted to the UART using interrupts. Blocks if it can not write the whole string into the circular buffer.
s | program memory string to be transmitted |
void uart1_init | ( | unsigned int | baudrate | ) |
Initialize USART1 (only available on selected ATmegas)
unsigned int uart1_getc | ( | void | ) |
Get received byte of USART1 from ringbuffer. (only available on selected ATmega)
void uart1_putc | ( | unsigned char | data | ) |
Put byte to ringbuffer for transmitting via USART1 (only available on selected ATmega)
void uart1_puts | ( | const char * | s | ) |
Put string to ringbuffer for transmitting via USART1 (only available on selected ATmega)
void uart1_puts_p | ( | const char * | s | ) |
Put string from program memory to ringbuffer for transmitting via USART1 (only available on selected ATmega)