avr-uart
AVR UART Library
|
Interrupt UART library using the built-in UART with transmit and receive circular buffers. More...
Macros | |
#define | USART0_ENABLED |
#define | UART_RX0_BUFFER_SIZE 128 |
#define | UART_RX1_BUFFER_SIZE 128 |
#define | UART_RX2_BUFFER_SIZE 128 |
#define | UART_RX3_BUFFER_SIZE 128 |
#define | UART_TX0_BUFFER_SIZE 128 |
#define | UART_TX1_BUFFER_SIZE 128 |
#define | UART_TX2_BUFFER_SIZE 128 |
#define | UART_TX3_BUFFER_SIZE 128 |
#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))-1)|0x8000) |
UART Baudrate Expression for ATmega double speed mode. More... | |
#define | UART_FRAME_ERROR 0x0800 |
#define | UART_OVERRUN_ERROR 0x0400 |
#define | UART_BUFFER_OVERFLOW 0x0200 |
#define | UART_NO_DATA 0x0100 |
#define | uart_init(b) uart0_init(b) |
Macro to initialize USART0 (only available on selected ATmegas) More... | |
#define | uart_getc() uart0_getc() |
Macro to get received byte of USART0 from ringbuffer. (only available on selected ATmega) More... | |
#define | uart_peek() uart0_peek() |
Macro to peek at next byte in USART0 ringbuffer. | |
#define | uart_putc(d) uart0_putc(d) |
Macro to put byte to ringbuffer for transmitting via USART0 (only available on selected ATmega) More... | |
#define | uart_puts(s) uart0_puts(s) |
Macro to put string to ringbuffer for transmitting via USART0 (only available on selected ATmega) More... | |
#define | uart_puts_p(s) uart0_puts_p(s) |
Macro to put string from program memory to ringbuffer for transmitting via USART0 (only available on selected ATmega) More... | |
#define | uart_available() uart0_available() |
Macro to return number of bytes waiting in the receive buffer of USART0. More... | |
#define | uart_flush() uart0_flush() |
Macro to flush bytes waiting in receive buffer of USART0. More... | |
#define | uart_puts_P(__s) uart0_puts_p(PSTR(__s)) |
Macro to automatically put a string constant into program memory. More... | |
#define | uart0_puts_P(__s) uart0_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 of USART1. More... | |
#define | uart2_puts_P(__s) uart2_puts_p(PSTR(__s)) |
Macro to automatically put a string constant into program memory of USART2. More... | |
#define | uart3_puts_P(__s) uart3_puts_p(PSTR(__s)) |
Macro to automatically put a string constant into program memory of USART3. More... | |
Functions | |
void | uart0_init (uint16_t baudrate) |
Initialize UART and set baudrate. More... | |
uint16_t | uart0_getc (void) |
Get received byte from ringbuffer. More... | |
uint16_t | uart0_peek (void) |
Peek at next byte in ringbuffer. More... | |
void | uart0_putc (uint8_t data) |
Put byte to ringbuffer for transmitting via UART. More... | |
void | uart0_puts (const char *s) |
Put string to ringbuffer for transmitting via UART. More... | |
void | uart0_puts_p (const char *s) |
Put string from program memory to ringbuffer for transmitting via UART. More... | |
uint16_t | uart0_available (void) |
Return number of bytes waiting in the receive buffer. More... | |
void | uart0_flush (void) |
Flush bytes waiting in receive buffer. | |
void | uart1_init (uint16_t baudrate) |
Initialize USART1 (only available on selected ATmegas) More... | |
uint16_t | uart1_getc (void) |
Get received byte of USART1 from ringbuffer. (only available on selected ATmega) More... | |
uint16_t | uart1_peek (void) |
Peek at next byte in USART1 ringbuffer. | |
void | uart1_putc (uint8_t 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... | |
uint16_t | uart1_available (void) |
Return number of bytes waiting in the receive buffer of USART1. | |
void | uart1_flush (void) |
Flush bytes waiting in receive buffer of USART1. | |
void | uart2_init (uint16_t baudrate) |
Initialize USART2 (only available on selected ATmegas) More... | |
uint16_t | uart2_getc (void) |
Get received byte of USART2 from ringbuffer. (only available on selected ATmega) More... | |
uint16_t | uart2_peek (void) |
Peek at next byte in USART2 ringbuffer. | |
void | uart2_putc (uint8_t data) |
Put byte to ringbuffer for transmitting via USART2 (only available on selected ATmega) More... | |
void | uart2_puts (const char *s) |
Put string to ringbuffer for transmitting via USART2 (only available on selected ATmega) More... | |
void | uart2_puts_p (const char *s) |
Put string from program memory to ringbuffer for transmitting via USART2 (only available on selected ATmega) More... | |
uint16_t | uart2_available (void) |
Return number of bytes waiting in the receive buffer of USART2. | |
void | uart2_flush (void) |
Flush bytes waiting in receive buffer of USART2. | |
void | uart3_init (uint16_t baudrate) |
Initialize USART3 (only available on selected ATmegas) More... | |
uint16_t | uart3_getc (void) |
Get received byte of USART3 from ringbuffer. (only available on selected ATmega) More... | |
uint16_t | uart3_peek (void) |
Peek at next byte in USART3 ringbuffer. | |
void | uart3_putc (uint8_t data) |
Put byte to ringbuffer for transmitting via USART3 (only available on selected ATmega) More... | |
void | uart3_puts (const char *s) |
Put string to ringbuffer for transmitting via USART3 (only available on selected ATmega) More... | |
void | uart3_puts_p (const char *s) |
Put string from program memory to ringbuffer for transmitting via USART3 (only available on selected ATmega) More... | |
uint16_t | uart3_available (void) |
Return number of bytes waiting in the receive buffer of USART3. | |
void | uart3_flush (void) |
Flush bytes waiting in receive buffer of USART3. | |
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_RXn_BUFFER_SIZE and UART_TXn_BUFFER_SIZE constants define the size of the circular buffers in bytes. Note that these constants must be a power of 2.
You need to define these buffer sizes as a symbol in your compiler settings or in uart.h
See README.md for more detailed information. Especially that relating to symbols: USARTn_ENABLED and USARTn_LARGE_BUFFER
#define uart1_puts_P | ( | __s | ) | uart1_puts_p(PSTR(__s)) |
Macro to automatically put a string constant into program memory of USART1.
#define uart2_puts_P | ( | __s | ) | uart2_puts_p(PSTR(__s)) |
Macro to automatically put a string constant into program memory of USART2.
#define uart3_puts_P | ( | __s | ) | uart3_puts_p(PSTR(__s)) |
Macro to automatically put a string constant into program memory of USART3.
#define uart_available | ( | ) | uart0_available() |
Macro to return number of bytes waiting in the receive buffer of USART0.
#define UART_BAUD_SELECT | ( | baudRate, | |
xtalCpu | |||
) | (((xtalCpu)+8UL*(baudRate))/(16UL*(baudRate))-1UL) |
#define UART_BAUD_SELECT_DOUBLE_SPEED | ( | baudRate, | |
xtalCpu | |||
) | ((((xtalCpu)+4UL*(baudRate))/(8UL*(baudRate))-1)|0x8000) |
#define UART_BUFFER_OVERFLOW 0x0200 |
#define uart_flush | ( | ) | uart0_flush() |
Macro to flush bytes waiting in receive buffer of USART0.
#define uart_getc | ( | ) | uart0_getc() |
Macro to get received byte of USART0 from ringbuffer. (only available on selected ATmega)
#define uart_init | ( | b | ) | uart0_init(b) |
Macro to initialize USART0 (only available on selected ATmegas)
#define uart_putc | ( | d | ) | uart0_putc(d) |
Macro to put byte to ringbuffer for transmitting via USART0 (only available on selected ATmega)
#define uart_puts | ( | s | ) | uart0_puts(s) |
Macro to put string to ringbuffer for transmitting via USART0 (only available on selected ATmega)
#define uart_puts_p | ( | s | ) | uart0_puts_p(s) |
Macro to put string from program memory to ringbuffer for transmitting via USART0 (only available on selected ATmega)
#define uart_puts_P | ( | __s | ) | uart0_puts_p(PSTR(__s)) |
#define UART_RX0_BUFFER_SIZE 128 |
#define UART_RX1_BUFFER_SIZE 128 |
#define UART_RX2_BUFFER_SIZE 128 |
#define UART_RX3_BUFFER_SIZE 128 |
#define UART_TX0_BUFFER_SIZE 128 |
#define UART_TX1_BUFFER_SIZE 128 |
#define UART_TX2_BUFFER_SIZE 128 |
#define UART_TX3_BUFFER_SIZE 128 |
uint16_t uart0_available | ( | void | ) |
Return number of bytes waiting in the receive buffer.
uint16_t uart0_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 uart0_init | ( | uint16_t | baudrate | ) |
Initialize UART and set baudrate.
baudrate | Specify baudrate using macro UART_BAUD_SELECT() |
uint16_t uart0_peek | ( | void | ) |
Peek at next byte in ringbuffer.
Returns the next byte (character) of incoming UART data without removing it from the internal ring buffer. That is, successive calls to uartN_peek() will return the same character, as will the next call to uartN_getc().
UART_NO_DATA is returned when no data is available.
void uart0_putc | ( | uint8_t | data | ) |
Put byte to ringbuffer for transmitting via UART.
data | byte to be transmitted |
void uart0_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 uart0_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 |
uint16_t uart1_getc | ( | void | ) |
Get received byte of USART1 from ringbuffer. (only available on selected ATmega)
void uart1_init | ( | uint16_t | baudrate | ) |
Initialize USART1 (only available on selected ATmegas)
void uart1_putc | ( | uint8_t | 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)
uint16_t uart2_getc | ( | void | ) |
Get received byte of USART2 from ringbuffer. (only available on selected ATmega)
void uart2_init | ( | uint16_t | baudrate | ) |
Initialize USART2 (only available on selected ATmegas)
void uart2_putc | ( | uint8_t | data | ) |
Put byte to ringbuffer for transmitting via USART2 (only available on selected ATmega)
void uart2_puts | ( | const char * | s | ) |
Put string to ringbuffer for transmitting via USART2 (only available on selected ATmega)
void uart2_puts_p | ( | const char * | s | ) |
Put string from program memory to ringbuffer for transmitting via USART2 (only available on selected ATmega)
uint16_t uart3_getc | ( | void | ) |
Get received byte of USART3 from ringbuffer. (only available on selected ATmega)
void uart3_init | ( | uint16_t | baudrate | ) |
Initialize USART3 (only available on selected ATmegas)
void uart3_putc | ( | uint8_t | data | ) |
Put byte to ringbuffer for transmitting via USART3 (only available on selected ATmega)
void uart3_puts | ( | const char * | s | ) |
Put string to ringbuffer for transmitting via USART3 (only available on selected ATmega)
void uart3_puts_p | ( | const char * | s | ) |
Put string from program memory to ringbuffer for transmitting via USART3 (only available on selected ATmega)