The inspiration for this bit of code came from a couple sources. There is a great and simple UART tutorial on Sparkfun that got me started when all other tutorials failed me. Additionally, reading the AVR Freaks forums, I educated myself on more advanced UART techniques including a suggestion by Dean, I believe, to use ring buffers to store data and handle transmitting/receiving the data in interrupt routines.
In my library, I have the following data structures:
volatile char in;
volatile char out;
volatile uint8_t inptr;
volatile uint8_t outptr;
and the following routines:
uart_send_string(const char* s);
In the next few paragraphs, I’ll show you how these are used, but first, let’s take a quick look at the data structures.