Library for the UART on the ATmega328/P.
- Polling implementation
- Interrupts implementation
- Formatted IO streams implementation
- ATmega328/P
- AVR-GCC
- Download the repository.
- Take a look at the documentation.
- Use the examples inside
/ATmega328_UART/examples/
.
Prerequisites: AVR-GCC and Make
- Open
.../ATmega328_UART/Makefile
and edit the variables:$HOST_PLATFORM
,$F_CPU
and$UART_BAUD
. - Execute
> make
inside.../ATmega328_UART/
to recompile the library according to the specified frequency and baud rate.
❕ The library must be recompiled every time
$F_CPU
and/or$UART_BAUD
variables are changed!
- Open the
Makefile
that is in the root directory of the chosen example (e.g./ATmega328_UART/examples/IO_streams/Makefile
) and edit the variables:$HOST_PLATFORM
,$F_CPU
,$PROGRAMMER
and$PORT
. - Execute
> make
inside the same directory to build the example. - And finally execute
> make program
to upload it to the AVR target.
This is the same as 'Building and uploading an example' except that the Makefile
should be configured for the new project (e.g. the target name, the new location of the library, etc).
The library can be compiled and linked to a project using a different build system (e.g. a user's Makefile
, an IDE, etc). The location of the header file is .../ATmega328_UART/include/ATmega328_UART.h
and the location of the source file is ../ATmega328_UART/src/ATmega328_UART.c
.
F_CPU
andBAUD
macros must be defined.
❕ The library must be recompiled every time
F_CPU
and/orBAUD
macros are changed!
When using formatted IO streams, the libraries printf and/or scanf should be linked1. AVR-GCC linker flags:
-Wl,-u,vfprintf -lprintf_min
-Wl,-u,vfprintf -lprintf_flt -lm
-Wl,-u,vfscanf -lscanf_min
-Wl,-u,vfscanf -lscanf_flt -lm
The MIT License (MIT)
Copyright (c) 2019 Vasil Kalchev
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
1. avr-libc: <stdio.h> documentation