Serial Port Communication using AVR-GCC with Atmega32 MCU
As I had already written in previous entry that Atmega32 is based on AVR architecture and various C-syntax compilers are available for programming it. I have been using AVR-GCC compiler and edit my code files using AVR Studio which requires WinAVR to be pre-installed to enable to compile AVR-GCC.
Anyway, the task which I am going to describe is to get some character looped back through the MCU. That is to say, when we press a key in the HyperTerminal window the same character should be received by the MCU and transmitted back over the USART interface.
The first thing is the hardware. I have used a MAX232 chip, which is a RS-232 to TTL voltage converter and vice-versa. It is necessary to use this chip between the MCU and the serial port of the computer because the voltage levels of two interfaces do not co-incide. I have attached the detailed circuit diagram and corrected code, which has been taken from Bibin John’s AVR Book.
This whole implementation has taken around a week and a lot of highs and lows emotional energy. Initially the programmer I was using caused a few problems but that was duly corrected. Then the MAX232 chip was malfunctioning so I replaced it. Finally the code itself had a mistake which I corrected by subscribing to help of various people on Orkut communities, Amol Deshmukh from IIT Mumbai and AVRfreaks.
Here’s the end result of all this labour: