Using ATmega32 with Arduino IDE

Over time I have used all kinds of Atmel microcontrollers in various projects.

One of the most suitable was ATmega32.
I have a small collection of development boards for Atmega32/16,  some bought as-is,  some made ​​on stripboard.

Although the original Arduino boards offers a pleasant experience and a rapid development of the projects, when it was necessary to extract” these projects to give them final shape I hit the well-known problem: arduino board must be locked in the project.

It is not only the price. Although a microcontroller in thru-hole package is significantly bigger than SMD version, it is still much smaller than an Arduino board.

And still I want to use the Arduino IDE to benefit from the collection of  (very well made) libraries  ready to use.

So I gathered together information useful for this purpose.

Things you will need:

  1. Atmega32 microcontroller. 🙂
  2. Programmer (any programmer recognized by Arduino IDE).  I use the USBasp programmer.
  3. Minimal setup for power-up Atmega32 microcontroller (breadboard, stribpoard or  a classical development board. )

Software set-up

  1. Download project https://github.com/eaconner/ATmega32-Arduino/archive/master.zip or ATmega32-Arduino-master.
  2. Locate file boards.txt in arduino folder  …arduino-1.5.2\hardware\arduino\avr\boards.txt
  3. Append information from zip archive boards.txt to original boards.txt
  4. Make a folder named mega32 in …arduino-1.5.2\hardware\arduino\avr\variants
  5. Copy file pins_arduino.h from the zip into folder created at step 4.
  6.  Start Arduino IDE and select board.
    Atmega32-ArduinoIDE
  7. Select programmer.
    ArduinoScreenShot2

Atmega32 / Arduino Pinout

Atmega32Now you can try some simple examples that are already in Arduino.

Be very careful about correlation between ARDUINO pin and microcontroller pin.

Note: I also published this article on Instructables.

After some comments on Instructables article I found two errors in the file pins_arduino.h

Please note, since it is not my project can not correct them at the source (https://github.com/eaconner/ATmega32-Arduino/).

So I’ll post here the errors and correct values.

erroneous definition of SCL and SDA

const static uint8_t SDA = 8; //wrong
const static uint8_t SCL = 9; //wrong

must be changed in:

const static uint8_t SDA = 17; //correct
const static uint8_t SCL = 16; //correct

Related posts:

http://openhardware.ro/atmega-40-pin-minimal-board/

http://openhardware.ro/using-atmega1284-arduino-ide/

http://openhardware.ro/using-atmega16-with-arduino-ide/

UPDATE:

For Serial library to work properly must be made following changes to the file HardwareSerial.cpp
In …\arduino-1.5.8\hardware\arduino\avr\cores\arduino\HardwareSerial.cpp

we will replace:

with:

 

Updated: April 9, 2015 — 6:11 pm

26 Comments

Add a Comment
  1. Just accidentally came here . Really compact and NICE instructions.
    You can make standalone projects using this information.

  2. Wow! Really helpful info. I, however, found out the attachInterrupt() arduino function does not work with atmega32 .Any help?

    1. No… attachInterrupt() is working with newer PCINT interrupt.

      Atmega32 and Atmega16 (and Atmega8) do not have this interrupt…

      The only solution is to switch to newer Atmega1284 / Atmega1284P/ Atmega644 … they have PCINT interrupt and are similar to Atmega32.

      1. I think that what I said above is not entirely true…
        It is true that ATmega32/16/8 not have PCINT interrupt (Pin Change Interrupt)…
        But I am not so sure about how this affected attachInterrupt()

        I can not give an (well documented) answer right now …
        I hurried to correct erroneous information

        The answer is somewhere in arduino-1.6.7/hardware/arduino/avr/cores/arduino/WInterrupts.c 🙂

  3. Hi Guys,

    I developed a scketch to work on Arduino Mega and I need to compile in an AtMega1284p-pu
    – Can I compile the same scketch in Atmega1284p-pu?
    – Is it necessary to change anything on the scketh? pins for example?
    – The AtMega1284p-pu is still a “virgin”, which Arduino’s bootloader is better to burn in?

    Thanks

    Angelo Ventura

    1. “Can I compile the same scketch in Atmega1284p-pu?” – Yes

      “Is it necessary to change anything on the scketh?” – Depends.
      You will probably need to use other pins than Arduino Mega.
      (as you can see Arduino Mega is based on Atmega 1280 or 2560 and has 54 pins)
      Atmega 1284P has 40 pins, so probabily you have to adjust your project schematics,
      and as a consequence… the code(scketch)

      “which Arduino’s bootloader is better to burn in” … my personal choice… best bootloader is without bootloader”, 🙂 … I always use a programmer (like USBASP)

      and because it is about new/ blanc microcontroller, the most IMPORTANT thing is to put fusebits according to your needs/usage…
      you can run Atmega1284 at max speed 20MHz … or you can run at other speed … 16MHz like Arduino Mega,you can use with external quartz or resonator or internal oscillator…
      there are many possibilities, you must study a good tutorial about fusebits and make your decisions about your specific project…

      And if you have more questions we can discuss further..

      Regards!

  4. hey hii friends i m using open hardware for atmega32 but i found mapping of adc is wrong i means if A0 is selected then actually it is A1

  5. hi. i want to monitor values on IDE serial monitor but it not working. would you help me please.

    1. I’d like to help but I have too little information. What does not work exactly?
      What kind of hardware setup do you have? MAX323… USB to serial…
      What operating system are you using? Windows… Linux… Arduino IDE version…
      It could be the drivers for USB-to-serial… or Arduino IDE version…

      1. Hello . thank you for your attention.
        i made this board:
        http://www.instructables.com/id/ATmega-DIP40-in-Arduino-IDE-164/

        and i used ‘arduino as isp’ for programing that.(and i test pl2303 usb to serial adapter as programer too)
        when i want to see results, Arduino Serial Monitor window does not show anything
        for example:

        void setup() {
        Serial.begin(9600);
        }
        void loop() {
        Serial.println(“Hello”);
        delay(1000);
        }

        I have another question. Can I program the board through RX & TX pins.
        thank you.

        1. operating system: Windows 8.1 and windows 10
          Arduino IDE version 1.6.11
          I’ve used the following adapters:
          1- Arduino UNO (Arduino as ISP)
          2- PL2303 usb to serial Adapter
          3- FT232 usb to serial Adapter

          1. 🙂 Hm… this is not working in that way… You are close, but you have to expand your knowledge about serial/USART/RS232 link between a MCU and computer.

            So… I can’t answer in comment section because, I should respond to several comments that relate to each other … so I can’t imagine how to split my answer across these comments.

            So I have a better idea: I will write a new blog post where I will try to make a tutorial about these things, a tutorial to respond to all the issues I’ve seen in comments here (or elsewhere in this site, about serial, usart, bootloader…).

            I set to myself a deadline of 7 days from now to complete such a tutorial.
            So … stay tuned for next days

            1. ok.i am looking forward to your new blog posts
              thanks a lot. 🙂

            2. hello Silvius. do you complete this tutorial. Please notify me when done. thanks

              1. Not yet, not yet. I am working on it…
                I will definitely announce you. 🙂

                1. thanks a lot and best regards. 🙂

              2. http://openhardware.ro/about-stand-alone-arduino-and-serial-port/

                It took longer than I thought. In fact is not a tutorial … It’s what I could not say in comments…
                You will see why … 🙂

                1. Thanks Silvius
                  🙂

      2. Hello . thank you for your attention.
        i made this board:
        http://www.instructables.com/id/ATmega-DIP40-in-Arduino-IDE-164/

        and i used IDE 1.6.11 & ‘arduino as isp’ for programing that.(and i test pl2303 usb to serial adapter as programer too)
        when i want to see results, Arduino Serial Monitor window does not show anything
        for example:

        void setup() {
        Serial.begin(9600);
        }
        void loop() {
        Serial.println(“Hello”);
        delay(1000);
        }

        I have another question. Can I program the board through RX & TX pins.
        thank you.

    2. I want to do that too. If u found an answer please tell me…

      1. 🙂 Actually to me go smoothly …I used the USART from ATmega16 and ATmega32 (and 1284).

        I used my development board from here: http://openhardware.ro/mini-avr40-board/
        and this rs232 module (DIY style): http://openhardware.ro/rs232ttl-board/

        Right now I’m working on a project using the USART for RS485 interface and everything works well …

        but over time I have used other types of development boards with RS232/RS485/USB-to-Serial interface included…

        What I meant is that I can not answer the question “Why serial link between the MCU and computer not working?” … because it could be many causes, and and I know nothing about your hardware and software setup.

  6. Great information. Thank you. Struggled to use Atmel Studio 7 IDE. going to try this instead.

  7. i have compiled for ethernet project and it shows low data memory but atmega32 has 2kb RAM…so how to change the RAM size mentioned in the definitions.

    1. I have compiled some examples of Ethernet examples with Arduino 1.6.12 and Atmega32 and worked OK. for Using atmega32 with arduino 1.6.xx please read this article:

      http://openhardware.ro/atmega-dip40-in-arduino-ide-1-6-4/

      I do not use 1.5.xx or older, and no longer have installed it.

Leave a Reply

Your email address will not be published. Required fields are marked *

OpenHardware.Ro © 2017 Frontier Theme