Programming AVR USART with AVR-GCC. Part 2

In previous part of USART tutorial we have discussed about simplest 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 actually data will be received, so 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 is empty. In this case we have empty transmit buffer UDR0 and Transmit Shift Register. After this interrupt there is no physical transmission on pins. This feature is usually used in half duplex transmission mode when transmitter and receiver share same line like in RS-485 standard.

So if we need to use single line and be able to transmit and receive data – use Half Duplex mode and TX complete interrupts. If we need to transmit data in one direction only, for instance serial LCD using TX Complete interrupt is impractical because we get gaps between transmitted frames and loose transmission rate. In such case it is more practical to use Tx Data Register Empty interrupt. This interrupt occurs just after data from transmit buffer is sent to transmit shift register. In this case UDR0 is ready to receive data while previous is being transmitted. In this case we get “chain” like transmission without gaps between frames. Read more »

Arduino controlled LED sneakers

Your old sneakers look boring, then grab a bunch of LEDs, Arduino and make them shiny. In this project each sneaker is surrounded by single color LEDs that are controlled by Arduino.

LEDs can can go through 6 different patterns that are selected by activating reed sensor with magnet. Really simple and effective solution. There is one more thing – probably you will have to learn walking with these as LEDs are popping out to sides and it is quite easy to crash when foots get to close. Anyway, great and fun project.