About Code Examples

There are three projects available in the zip file which comes with this application note, one for UART and two for USART. Each of these projects contains two source files (polling method and interrupt method). The projects contain the code example for polling method. To test interrupt method, the corresponding file can be added to the project after removing the existing source file.

UART based examples are tested for ATmega8515 device and USART based ones are tested on ATmega324PB and ATtiny104 . All Six files can be rebuild using avr-gcc or IAR Toolchain and can be used on any AVR ATtiny® and AVR ATmega® devices with minor changes if any such as register name or register bit name. Baudrate calculations in these examples are based on 8MHz and 1MHz (ATtiny104) CPU clock frequency. The main application stays in an infinite loop and sends back the data byte received.

The interrupt handling routines uses modulo 2n addressing of circular buffers for buffering incoming and outgoing data. The buffer sizes must be defined before using the routines. Set the UART_RX_BUFFER_SIZE and UART_TX_BUFFER_SIZE variables to the buffer size in bytes. These variables must be a power of 2 for the given example, if not, a compiler error message will be flagged.

Note: The interrupt handling for ATtiny104 does not use circular buffering incoming and outgoing data to reduce RAM usage.