|
uart 1.0
AVR mega series uart library
|
Source file with implementation of polling-based UART functions and macros. More...
#include "uart.h"
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. | |
| UART_Data | uart_scanchar (char *data) |
| Non-blocking check for received UART data with error handling. | |
| char | uart_getchar (UART_Data *status) |
| Blocking receive single character via UART. | |
| 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. | |
| UART_Error | uart_error_flags (void) |
| Check and clear UART receive error flags. | |
Source file with implementation of polling-based UART functions and macros.
This file contains the definitions of function implementations for polling-based UART communication on AVR-Mega-Series microcontrollers. Supports configurable baud rates, frame formats, optional echo, and stdio integration (printf/scanf).
| 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).
