Turn-key PCB assembly services in prototype quantities or low-volume to mid-volume production runs

Programming AVR USART with AVR-GCC. Part 2

In the previous part of the USART tutorial, we have discussed the most straightforward way of implementing USART transmitting and receiving routines. These are OK to use, but in more intense and power critical applications they are not practical and efficient. Firs of all using loops to poll for transmitting buffer to be ready or wait for received byte consumes lots of processing power what also leads to more power consumption. In reception mode we cant predict when actual data will be received, so the program has to check for received data indicating flag constantly and don’t miss it as next upcoming byte may clear it. So there is a better way of using USART – so-called Interrupt Driven USART. USART Interrupt sources If you look into datasheet you will find that USART0 in Atmega328 has three interrupt sources: TX Complete; TX Data Register Empty; RX Complete. Probably a natural question comes out: Why there are two interrupts for transmission? Explanation is simple. Lets take TX Complete interrupt. It will occur when Transmit Shift Register has been shifted out and… Continue reading