Paths

Serial Port Communication using AVR-GCC with Atmega32 MCU

Posted in Final Year Project, Telecommunications by Rakesh on February 12, 2007

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:

serial_comm-working.JPG

28 Responses

Subscribe to comments with RSS.

  1. Ayaz Ahmed Khan said, on February 22, 2007 at 7:31 pm

    Commendable effort and interesting achievement, Rakesk!

  2. Ankesh Verma said, on March 30, 2007 at 2:12 am

    hello ayaz ahmed khan ….
    i found this poject very interesting….
    even i am in final year and i think i can present this as my final year project.
    so please do me a fevor, please send me more detail about this project ….
    i will be highly oblized….
    thankyou

  3. SoogyKnottjog said, on February 24, 2008 at 5:14 pm

    Amber acts Jenny’s possies through her pajamas, with each nude celeb movies crisscrossing quicker to her slaping pussy. I was fuming to excite tired, and I felt my euphemism overlapping shakingly in time.

  4. Pavan Kumar said, on June 22, 2008 at 12:55 pm

    Hei thatnks for the info!

    The schematic u have is perfect n is self explanatory!
    again thanks fr the posting

  5. Pavan Kumar said, on June 29, 2008 at 9:05 pm

    Hello!

    I have built the circuit as shown in the circuit diagram. Now i have got a question!!!

    What should i do with the following atmega32 pins:
    pin 6 – MOSI
    pin 7 – MISO
    pin 8 – SCK
    pin 9 – RESET

    Where do i connect them in order for me to program my atmega32 through a serial port??

    Plss let me know
    Thank you

  6. Rakesh said, on June 30, 2008 at 5:29 pm

    Hey Pavan,

    Well the pins that you have mentioned are used to program ATMEGA32 via Parallel port and not serial port. So you need to check that out in the other post I have on this blog.

  7. Pavan Kumar said, on June 30, 2008 at 10:32 pm

    Well thats the confusion,
    coz i have made all the connections just the way they r shown in the circuit diagram u have mentioned where just 2 pins of atmega32 (14 and 15) are connected to max 232 ic.

    when i try programming with pony prog in serial mode setting through com1 even the probe test fails, indicating some problem in the circuit. so i have double checked the circuit and even took help of frnds to check it (just to be sure). To my dismay i couldnot find even a single soldering or a connection problem.

    I have a working parallel port programmer but i am in bad need of serial programmer as i have a laptop with vista loaded onto it (damn it). and also i have a USB to rs232 convertor.

    So i desperately want to get the circuit working. (This may sound dumb but is the circuit diagram mentioned above COMPLETE in itself) Meaning is every thing shown over there, coz when i checked Bibins book quoted above the pics there show a parallel port also being used along with a serial port!!!!

    1.So is it possible to use just a serial rs232 cable to program an atmega32?
    2.Is the circuit mentioned above complete in itself??
    3.Are any modifications necessary to the above circuit to program atmega32 just with a serial db9 cable??

    Plss let me know,
    N thanks for the reply

  8. Rakesh said, on July 1, 2008 at 4:53 pm

    Pavan, you can only use the schematic given in here to program the MCU via Parallel port. To answer your questions:

    1. Yes, there are other schematics which allow you to do that. There’s this bootloader option, you might want to check and search the forums of http://www.avrfreaks.net for programming these kind of MCUs via serial port. This is NOT the schematic for that and pony prog’s serial mode won’t work with this.

    2. Yes it is complete if you want and can use parallel port.

    3. Unfortunately that would be a whole new schematic, google it. I don’t have experience on using that method but that won’t be whole lot difficult I suppose. You might just need to install a boot-loader inside the MCU initially via parallel port programmer somehow and then you can use serial port (same port that you’d use for data communication) for programming it.

    So you really need to explore those boot-loader options that I have never have. Do post your comments here if you finally get one of those working or fail miserably.

    Good Luck.

  9. Ramesh Moon-from MAXACTO said, on July 12, 2008 at 5:45 pm

    You can program the AVR family by using parallel port or serial port. but for parallel port (which is very simple & less hardware) special driver is required in windows XP. Serial port programming is also easy & it requires very few components. The software we should use is AT-PROG. You will get the programmer circuits in that.

  10. Muhammad Saqlain said, on July 30, 2008 at 8:49 am

    Can you please guide me how to get more than one serial port interfaces in AVR

    Thanks

  11. Rakesh said, on July 30, 2008 at 9:12 am

    There are some microcontrollers available in AVR family which have more than one UART port on them. You need to search Atmel’s catalog for that, I do remember spotting a few.

  12. Muhammad Saqlain said, on July 30, 2008 at 10:58 pm

    Thanks Mr Rakesh. The AVRs your taking about are not available in the market so i am trying to interface UART. Can you help me in this regard
    Thanks

  13. Rakesh said, on July 31, 2008 at 9:17 am

    Well this blog has been originally written to ‘help’ you. If you have any particular difficulty in any aspect, do write here and me or somebody else would try and help you out. Do check out the long list of comments on this post, there are good chances that the problem you have may have been discussed here.

  14. Waqar said, on August 13, 2008 at 1:26 am

    Can we have the same value of capacitances around the oscillator even for freqs. other than 7.2 Mhz????

  15. Rakesh said, on August 13, 2008 at 2:52 pm

    @Waqar: You need to check the AVR’s datasheet for finding out what particular capacitance is required. I think there’s a table given in there, check it out, that would help.

  16. Waqar said, on August 15, 2008 at 11:26 am

    THX, but it isnt imp

  17. hadi said, on August 16, 2008 at 1:31 am

    hi i really very fantastic …

  18. somit said, on August 25, 2008 at 12:14 am

    hello………im from BIT Mesra…..

    I feel theres a lot confusion here…………lemme comment a bit…………..

    The circuit above is just a communication circuit ( its not for programming)…………………………….. for programming u need miso,mosi,reset,etc……….which can be done through serial as well as parallel port……but the circuit for parallel port is an easy one……….the above circuit is using RXD and TXD….
    because that atmega32 is having BOOTLOADER installed in it ……..and booloader can be installed only via programmer ………(www.lancos.com)…………..UART communication needs bootloader to be installed……………..

  19. somit said, on August 25, 2008 at 12:17 am

    refer ………………….www.lancos.com

    http://www.societyof robots.com

  20. laxmikant said, on September 5, 2008 at 6:00 pm

    hi rakesh iam in last year .should you plz tell me what is the first procedure to program in win avr and avr gcc ,after downloading the setup

  21. pratik kotak said, on October 13, 2008 at 10:29 pm

    Hi Group,
    I m a final year student… From last 10 days i m working on programming of ATMega32 via parallel port…I have tried two or three programmer circuit and the software like VMLAB, pony prog but didn’t get succeed… so pls anybody will suggest me which software should i use to program it. also provide circuit diagram or link….
    anybody can send their reply also on pratikkotak2006@yahoo.co.in.. Thank you…m in hurry….

  22. mantu said, on January 7, 2009 at 12:38 pm

    ANYBODY HAVE CIRCUIT DIGRAM AND CODES FOR ATMEGA32 BURNER?
    WAITING FOR A QUICK RESPONSE

  23. bhavs said, on January 8, 2009 at 2:04 am

    @somit
    u said tht the given diagram wil not be useful for dumping the programe so wat crkt diagram i use for serial port connection

  24. Naveen said, on March 4, 2009 at 2:00 pm

    @bhavs

    u can try this serial programmer

    this is for atmega 16 but u shud be able to locate the corresponding pins on any atmega MCU.

    http://home.iitk.ac.in/~sankule/robotics/avr/serial_programmer.html

  25. Absar said, on May 21, 2009 at 12:11 pm

    Hahah! This reminded me of my NERC days man! The thing with home-brew boards is that you never know where the problem might be – the hardware or the software! :P We always got stumped whenever our robot would stop working as expected – “Wait, is that because of our code, or are the H-bridges gone bonkers again!?”

  26. vinesh said, on June 10, 2009 at 1:43 am

    hey!!!! i m tryin 2 program atmega32 with the help of serial port….. but it is not getting connected at avr-gcc…………i have been using a laptop with xp installed…….i am using serial/usb port……..pls help me out……….i m dire straits here………..

  27. Avr serial port said, on July 10, 2009 at 1:32 am

    [...] Serial Port Communication using AVR-GCC with Atmega32 MCU « Paths You can program the AVR family by using parallel port or serial port. but for parallel port (which is very simple & less hardware) special driver is … gopchandani.wordpress.com/…/serial-port-communication-using-avr-gcc-with-atmega32-mcu/ – [...]

  28. Dan said, on October 7, 2009 at 8:54 pm

    So it is possible to use a crystal with a different frequency but to change the capacitors acording to atmel’s table? Because I only found a crystal at 7.159 MHz


Leave a Reply