This example demonstrates how to use the avr libc utility setbaud to find the correct settings for the UART baudrate registers.
This application will set up the UART according to the settings in the conf_uart.h file, baudrate is calculated using the avr libc setbaud utility. When initialization of the UART is done the application sends the letter 'A' on the UART and expect to receive the same letter, hence the hardware must be set up so that the TX and RX pin is shorted to create a loop back.
The util/setbaud tool is a tool offered by the avr libc library, and is a function for compile time calculation of the baudrate register of values. In application where run-time baudrate change is not needed this is a tool which easily calculates the best baudrate register settings while keeping the flash footprint at a minimum.
A common way of using the setbaud tool is:
This software was written for the GNU GCC for AVR.
Other compilers may or may not work.
For further information, visit Microchip.