|
uart 1.0
AVR mega series uart library
|
Header file with declarations and macros for hardware UART. More...
#include <stdio.h>#include <avr/io.h>#include <util/setbaud.h>#include "../../common/enums/UART_enums.h"

Go to the source code of this file.
Macros | |
| #define | F_CPU 12000000UL |
| System clock frequency definition. | |
| #define | UART_BAUDRATE 9600UL |
| Default UART communication baud rate. | |
| #define | BAUD UART_BAUDRATE |
| #define | UART_DATASIZE 8 |
| Number of data bits per frame (5-8). | |
| #define | UART_PARITY 0 |
| Parity bit configuration. | |
| #define | UART_STOPBITS 1 |
| Number of stop bits per frame (1-2). | |
| #define | UART_RXC_ECHO |
| Enables local echo of received characters. | |
| #define | UART_HANDSHAKE 0 |
| Flow control / handshaking mode. | |
| #define | UART_HANDSHAKE_XON 0x11 |
| XON character (transmit when ready to receive). | |
| #define | UART_HANDSHAKE_XOFF 0x13 |
| XOFF character (transmit when not ready to receive). | |
| #define | UART_STDMODE 1 |
| Standard I/O integration mode (printf/scanf). | |
Functions | |
| void | uart_init (void) |
| Initialize the UART hardware interface with configured parameters. | |
| void | uart_disable (void) |
| Disable the UART hardware interface and reset configuration. | |
| char | uart_putchar (char data) |
| Transmit a single character via UART (blocking). | |
| int | uart_printf (char data, FILE *stream) |
| UART printf stream handler for stdout redirection. | |
| char | uart_getchar (UART_Data *status) |
| Blocking receive single character via UART. | |
| UART_Data | uart_scanchar (char *data) |
| Non-blocking check for received UART data with error handling. | |
| UART_Error | uart_error_flags (void) |
| Check and clear UART receive error flags. | |
| int | uart_scanf (FILE *stream) |
| UART scanf stream handler for stdin redirection. | |
| void | uart_clear (void) |
| Clear UART input stream errors and discard pending character. | |
Header file with declarations and macros for hardware UART.
This file provides function prototypes, type definitions, and constants for hardware-based UART communication on AVR0 microcontrollers.
| #define BAUD UART_BAUDRATE |
| #define F_CPU 12000000UL |
System clock frequency definition.
This macro defines the operating frequency of the microcontroller's clock in Hertz. It is used for timing calculations. The value should match the actual hardware clock frequency to ensure correct timing behavior.
| #define UART_BAUDRATE 9600UL |
Default UART communication baud rate.
Sets the default serial communication speed to 9600 baud. Common values are 9600, 19200, 38400, 57600, 115200.
| #define UART_DATASIZE 8 |
Number of data bits per frame (5-8).
Configures the character length transmitted/received: Valid values: 5, 6, 7, 8, 9H, 9L (default: 8).
| #define UART_HANDSHAKE 0 |
Flow control / handshaking mode.
Configures flow control between communicating systems:
| #define UART_HANDSHAKE_XOFF 0x13 |
XOFF character (transmit when not ready to receive).
| #define UART_HANDSHAKE_XON 0x11 |
XON character (transmit when ready to receive).
| #define UART_PARITY 0 |
Parity bit configuration.
Selects parity checking for error detection:
| #define UART_RXC_ECHO |
Enables local echo of received characters.
When defined, each received character is automatically transmitted back through TX (echo effect). Useful for terminal applications.
| #define UART_STDMODE 1 |
Standard I/O integration mode (printf/scanf).
Enables avr-libc stdio functions over UART:
| #define UART_STOPBITS 1 |
Number of stop bits per frame (1-2).
Configures stop bits signaling frame end:
| void uart_clear | ( | void | ) |
Clear UART input stream errors and discard pending character.
Calls clearerr(stdin) and getchar() to reset stream state and discard any buffered input. Used to recover from scanf() failures.
| void uart_disable | ( | void | ) |
Disable the UART hardware interface and reset configuration.
This function completely disables the USART peripheral by clearing TXEN/RXEN bits and all interrupt enables. Call before reconfiguring UART or entering power-save modes.
| UART_Error uart_error_flags | ( | void | ) |
Check and clear UART receive error flags.
Reads RXDATAH error bits (FERR, BUFOVF, PERR) and clears by reading RXDATAL. Returns first detected error or UART_None if no errors.

| char uart_getchar | ( | UART_Data * | status | ) |
Blocking receive single character via UART.
| [out] | status | Pointer to receive UART_Data status (UART_Received/UART_Fault). |
Loops calling uart_scanchar() until data available or error occurs. Status indicates if data valid (UART_Received) or error (UART_Fault).


| void uart_init | ( | void | ) |
Initialize the UART hardware interface with configured parameters.
This function configures the USART peripheral for polling-based operation:
All configuration is derived from uart.h preprocessor macros.
| int uart_printf | ( | char | data, |
| FILE * | stream ) |
UART printf stream handler for stdout redirection.
| data | Character to transmit. |
| stream | FILE stream pointer (unused). |
Internal callback used by avr-libc fdevopen() for printf() redirection. Only compiled when UART_STDMODE == 1 or 2 (write support).

| char uart_putchar | ( | char | data | ) |
Transmit a single character via UART (blocking).
| data | Character byte to transmit (0-255). |
Polling implementation waits for DREIF (Data Register Empty) flag before writing to UDR register. Blocks until transmission completes.

| UART_Data uart_scanchar | ( | char * | data | ) |
Non-blocking check for received UART data with error handling.
| [out] | data | Pointer to store received byte (valid only if UART_Received returned). |
Checks RXCIF flag and validates frame using uart_error_flags(). Handles XON/XOFF software handshake if enabled. Echoes received data if UART_RXC_ECHO defined.


| int uart_scanf | ( | FILE * | stream | ) |
UART scanf stream handler for stdin redirection.
| stream | FILE stream pointer (unused). |
Internal callback used by avr-libc fdevopen() for scanf() redirection. Only compiled when UART_STDMODE == 1 or 3 (read support).
