The hal-avr0-uart is a lightweight uart hardware abstraction library for AVR0 microcontrollers. It provides a clean interface for uart initialization and communication while hiding direct register-level interaction from higher software layers. The library is intended for projects that want to separate low-level device startup code from application logic and establish a small, reusable system layer for AVR0 targets.
UARTconfiguration for AVR0 devices.UARTcommunication for AVR0 devices.- Encapsulation of low-level register access.
- Compact and reusable API for embedded projects.
- Foundation for layered HAL architectures.
The
hal-avr0-uartlibrary reduces coupling by providing a focused interface for essentialuartsystem services. This improves portability inside a project, keeps startup code organized, and makes higher-level modules easier to maintain.
hal/
├── common/
| └── enums/
| └── UART_enums.h
└── avr0/
└── uart/
├── uart.c
└── uart.h
The library can be downloaded (zip or tar), cloned or used as submodule in a project.
| Type | File | Description |
|---|---|---|
| Library | zip / tar | AVR0 uart library |
mkdir -p ./hal/
git clone https://github.com/0x007E/hal-common.git ./hal
mv ./hal/hal-common ./hal/common
mkdir -p ./hal/avr0
git clone https://github.com/0x007E/hal-avr0-uart.git ./hal/avr0
mv ./hal/avr0/hal-avr0-uart ./hal/avr0/uartgit submodule add https://github.com/0x007E/hal-common.git ./hal/common
git submodule add https://github.com/0x007E/hal-avr0-uart.git ./hal/avr0/uartAdditional parameters like uart baudrate, handshake, pin definitions and many more can be setup in the header file. A user friendly description can be found here.
#include "../hal/avr0/uart/uart.h"
int main(void)
{
uart_init();
uart_putchar('T');
uart_putchar('E');
uart_putchar('S');
uart_putchar('T');
uart_putchar('\n');
uart_putchar('\r');
UART_Data status = UART_Empty;
while (1)
{
printf("\n\rEnter character: ");
unsigned char data = uart_getchar(&status);
printf("\n\rCharacter: %c", data);
// Non-blocking
if(uart_scanchar(&data) == UART_Received)
{
printf("\n\rCharacter received: %c", data);
}
printf("\n\rEnter a number: ");
unsigned int value = 0;
if(scanf("%u", &value) == 1)
{
printf("\n\rNumber: %u", value);
}
else
{
uart_clear();
printf("\n\rError->NaN!");
}
}
}To use
floating pointwithprintf/scanfon theavr0platform, a guide howto configureMicrocip Studiocan be found in this blog entry.
| Type | Link | Description |
|---|---|---|
| AVR0-Series | megaAVR® 0-series family datasheet |
R. GAECHTER
