loading

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) (ready-to-use) libraries.

So I gathered together information useful for this purpose.

Step 1: 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).

We do not need all, photos above are for exemplification only.

Step 2: Software Set-up

  1. Download zip file attached to this instructables.
  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.
  7. Select programmer

Later edit:

I removed link to github projet where I originally found. As long as there source changed and not fit this instructable.

After a message from the author: Eric Conner, I put back link to github project where I originally found this library:

https://github.com/eaconner/ATmega32-Arduino

Note: Zip file attached to this article is an older version of above library. This will work as this instructable was written.

Over time, after some feedback I noticed that source from github has changed.

Also, in comments you will see references to some errors, and how to to correct it.

This article and answers from comments is relate to version attached here, not github (newer) version.

Step 3: Done.

It's done.

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

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

Here is blink example: Files->Examples->Basics->Blink

Pin13 Arduino == Pin19 (PD5) Atmega32

/*Blink
  Turns on an LED on for one second, then off for one second, repeatedly.
  This example code is in the public domain.
 */
 
// Pin 13 has an LED connected on most Arduino boards.
// give it a name:
int led = 13;

// the setup routine runs once when you press reset:
void setup() {                
  // initialize the digital pin as an output.
  pinMode(led, OUTPUT);     
}

// the loop routine runs over and over again forever:
void loop() {
  digitalWrite(led, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(1000);               // wait for a second
  digitalWrite(led, LOW);    // turn the LED off by making the voltage LOW
  delay(1000);               // wait for a second
}

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

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

Since I am not the author of the project on github, it is subject to change beyond my control.

So please use code attached to this instructable and make above modifications.

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

will replace:

#if defined(__AVR_ATmega8__)
	config |= 0x80; // select UCSRC register (shared with UBRRH) 
#endif

with:

#if defined(__AVR_ATmega8__) || defined(__AVR_ATmega32__) || defined(__AVR_ATmega16__)
	config |= 0x80; // select UCSRC register (shared with UBRRH) 
#endif

See also: https://www.instructables.com/id/ATmega-DIP40-Mini...

<p>hi Silvius</p><p>how to boot loader atmega32a with Arduino mega2560 board ? </p>
<p>hi Silvius!!</p><p>i m getting error of missing 'upload.tool' <br>configuration parameter, when uploading the code to Atmega 32 using <br>usbasp as programmer...plz help me in resolving the problem.</p>
<p>error while burning bootloader: missing 'bootloader.tool' configuration parameter</p><p>i am getting these error while i am trying to put bootloader in atmega32 and i am using usbasp as programmer, plz help me whr i am doing mistake</p>
<p>There are no bootloader in this setup. Just use USBASP to upload your code.</p>
<p>Hello Silvius, Great Job man, i follow your step and first Toggle all pins of my atmega32 and it work,then after i use i2c protocol for data read write it also work but when i try to use SPI protocol MOSI and slave select pin are toggle and SCK pin of SPI not toggle it continue high no change in that pin ,can you please provide some information on SPI or give example code so it's help me. Thank you.</p>
<p>error while burning bootloader: missing 'bootloader.tool' configuration parameter</p><p>i am getting these error while i am trying to put bootloader in atmega32 and i am using usbasp as programmer, plz help me whr i am doing mistake</p>
<p>hii silvius, nice work brother, i made that on arduino 1.6.9 ,but i install that atmega32 board as per ur other instuctable ,that is &quot;ATmega dip-40 in arduino ide 1.6.4.&quot; by simply providing ur link in preferences. now it shows error to softwareserial library as shown in pics.i am making this clone for the home security project.in that i want to use gsm module.can u provide solution for this problem.</p><p>thank you.</p>
<p>I think that softwareserial library use PCINT interrups. Atmega32/16/8 don't have PCINT at all. You can try same method as you mention above, with ATmega 1284... but Atmega1284 already have 2 serial... so no need to use software serial (unless you need 3 or more serials...)</p><p>Or you can try an old version of software serial library with atmega32 and old version of arduino ide ... 1.0.xx. </p><p>These are solutions that I see at the moment... maybe someone else come up with other solutions ...?</p>
<p>I tried following these instructions but when I tried saving the modified 'boards.txt' it said that i was not allowed to. I am an admin on this computer. I tried saving the file somewhere else and deleting the original 'boards.txt'. I then transferred the new version into the correct place. when I ran the program it said that the 'boards.txt' file was invalid. what am I doing wrong?</p>
<p>I can try to guess... I do not know what operating system you use and which version of the Arduino IDE... this instructable was written <strong>before</strong> the &quot;Arduino 1.6.xx&quot;. Use <strong>this article</strong> only with <strong>Arduino 1.5.xx (or lower)</strong></p><p>For newer versions I think is better to read an follow this instructable:<a href="https://www.instructables.com/id/ATmega-DIP40-in-Arduino-IDE-164/" rel="nofollow"> https://www.instructables.com/id/ATmega-DIP40-in-Ar...</a></p><p>I use Arduino IDE 1.6.7 in Linux Ubuntu 16 (also tested with windows 7).</p><p></p><p></p>
<p>Yes, I have done these. Thanks </p>
<p>Hello,</p><p>I'm having a problem with pin interrupts using this set-up</p><p>I can get INT0 and INT0 to work correctly, enabling the internal pull-up resistors and then using:</p><p> attachInterrupt(digitalPinToInterrupt(10), footOne, CHANGE); // Foot One - Pin 10</p><p> attachInterrupt(digitalPinToInterrupt(11), footTwo, CHANGE); // Foot Two - Pin 11</p><p>but if i try the same for INT2:</p><p>attachInterrupt(digitalPinToInterrupt(2), footThree, CHANGE); // Foot Three - Pin 02, </p><p>I the interrupt never gets triggered, despite each pin being set up in the same way with the same debouncing circuit. </p><p>Any ideas how to get INT2 to work correctly?</p><p>thanks </p>
<p>There is no quick solution to this ... I just did some tests...</p><p>It seems that the problem is in arduino core files<strong> WInterrupts.c</strong> and <strong>wiring_private.h</strong>, there should be added support for ATmega32/16, but I can't do that in so little time.</p><p>Anyway It's interesting &quot;bug&quot;... I never feel need to use INT2 until now... When I needed more external interrupts I moved to ATmega1284 and i use PCINT... </p><p>I think there are some modified cores ... but i don't now what are their limits.. try to study &quot;Sanguino&quot;, &quot;Bobuino&quot;, &quot;Mighty-1284P&quot;, I know about them, but I never study in detail...</p>I try to not modify too much default core files... to be easy to remake when arduino cores are upgraded... so I look inside <strong>WInterrupts.c</strong> and <strong>wiring_private.h</strong> but I can't see a quick solution...<br>
<p>Hi Silvus, Thanks so much for getting back to me!</p><p>For the particular application I managed to find a work-around:</p><p>(used the same interrupt pin for 2 of the switches, and send the output of one of the switches to a different digital pin, so that during the interrupt, the digital pin can be read and the correct switch chosen)</p><p>But next time if i need lots of interrupts I'll switch to a different chip! (my choice of the 32 was fairly arbitrary in this case as I'm new to micro controllers, all I knew was i needed more pins that the 328p)</p>
<p>a quick and dirty solution to use INT2:</p><p>put this in setup()</p><blockquote>MCUCR |= (1 &lt;&lt; ISC2);<br> GICR |= (1 &lt;&lt; INT2); <br> sei();</blockquote><p>and make a function exactly like this:</p><blockquote>ISR(INT2_vect)<br>{<br> // code for int2 .... <br>}</blockquote><p>you can put this function before.. or after main function (I tested with function after main()... )</p><p>so you can write something like this:</p><blockquote>ISR(INT2_vect)<br>{<br> // code for int2 .... <br> CHANGE();<br>}</blockquote><p>I tested right now and work ...</p>
<p>Thanks again for your help.<br><br>I've been coming across an other issue, digital pins 18 19 20 &amp; 21 aren't working properly. <br>I can't even get them to blink an LED</p><p>if i use the basic arduino example blink: it works correctly for the digital pins such as 15 16 17 22 &amp; 23, but if I chance the pin in the program and on the breadboard, nothing happens. any ideas?</p><p>////////////////////////////////////////////////</p><p>const int LED = 18;</p><p>// the setup function runs once when you press reset or power the board</p><p>void setup() {</p><p> // initialize digital pin as an output.</p><p> pinMode(LED, OUTPUT);</p><p>}</p><p>// the loop function runs over and over again forever</p><p>void loop() {</p><p> digitalWrite(LED, HIGH); // turn the LED on (HIGH is the voltage level)</p><p> delay(1000); // wait for a second</p><p> digitalWrite(LED, LOW); // turn the LED off by making the voltage LOW</p><p> delay(1000); // wait for a second</p><p>}</p>
<p>those pins have dual function I/O and JTAG. you must disable JTAG...</p><p>or by <strong>setting fusebits</strong> or <strong>by program</strong>... see this for more info:</p><p></p><p><a href="http://www.avrfreaks.net/forum/portc-and-jtag-disableenable" rel="nofollow">http://www.avrfreaks.net/forum/portc-and-jtag-disa...</a></p><p>for begining you can put this in setup function:</p><blockquote>MCUCSR = (1&lt;&lt;JTD);<br>MCUCSR = (1&lt;&lt;JTD);<br></blockquote><p>twice is not a mistake ...</p><p>Have fun!</p>
<p>Thanks! That's worked perfectly! hopefully I won't need to ask any questions as I've got all my inputs and outputs working!</p>
<p>hello</p><p>im geting this error</p><p>Library can't use both 'src' and 'utility' folders. Double check C:\Users\Touresina\Desktop\New Folder (2)\arduino-1.6.8\hardware\arduino\avr\libraries\Wire</p><p>Error compiling for board ATmega32.</p><p>please help me</p><p>thanks</p>
<p>I noticed that you use 1.6.8 ... I thought the latest version 1.6.7 ... :)</p><p>... this instructable was written <strong>before</strong> the &quot;Arduino 1.6.xx&quot;. Use <strong>this article</strong> only with <strong>Arduino 1.5.xx (or lower)</strong></p><p>For your version I think is better to read an follow this instructable:<a href="https://www.instructables.com/id/ATmega-DIP40-in-Arduino-IDE-164/" rel="nofollow"> https://www.instructables.com/id/ATmega-DIP40-in-Ar...</a></p>
<p>i have made changes like you said in ide files but now i am getting this error...</p><p>Arduino: 1.6.7 Hourly Build 2015/12/17 04:47 (Windows 8.1), Board: &quot;Arduino/Genuino Uno&quot;<br><br>Property line '?# See: http://code.google.com/p/arduino/wiki/Platforms' in file E:\Robotics\arduino-nightly-windows\arduino-nightly\hardware\arduino\avr\boards.txt is invalid<br><br>Error compiling.<br><br> This report would have more information with<br> &quot;Show verbose output during compilation&quot;<br> enabled in File &gt; Preferences.</p>
<p>Hm... this instructable was written <strong>before</strong> the &quot;Arduino 1.6.xx&quot;. Use <strong>this article</strong> only with <strong>Arduino 1.5.xx (or lower)</strong></p><p>For your version I think is better to read an follow this instructable:<a href="https://www.instructables.com/id/ATmega-DIP40-in-Arduino-IDE-164/" rel="nofollow"> https://www.instructables.com/id/ATmega-DIP40-in-Ar...</a></p><p>Last article was written for <strong>1.6.4</strong> but working even with 1.6.7. I use this in <strong>Arduino 1.6.7</strong> on Ubuntu (also tested on windows 7 64bit). Inside are defined six &quot;boards&quot;:</p><ul><li>ATmega16-8MHz<li>ATmega16-16MHz<li>ATmega32-8MHz<li>ATmega32-16MHz<li>ATmega1284-16MHz<li>ATmega1284-20MHz</ul>
<p>how to make arduino campatible circuit with this IC. </p>
<p>look here: <a href="https://www.instructables.com/id/ATmega-DIP40-Minimal-Board/" rel="nofollow"> https://www.instructables.com/id/ATmega-DIP40-Mini...</a> it is about any atmega dip 40 (diy minimal development board) it will work with atmega32 or atmega1284, or atmega16 ... </p>
There are two separate issues:<p>1. To install support files for Atmega32 in Arduino IDE.</p><p>2. To make USBASP work in your OS ( in your case Win 8.1)</p><p></p><p>You can look <a href="https://www.instructables.com/id/ATmega-DIP40-in-Arduino-IDE-164/" rel="nofollow">here</a> or <a href="https://www.instructables.com/id/ATmega-DIP40-in-Arduino-IDE-164/" rel="nofollow">here</a>. If you have trouble we can continue there...</p><p> </p>
<p>I do have Win 8.1 and ver. 1.6.7 Arduino IDE and there is no way to get IDE to recognized Atmega32. Would there be any help, please? Thanks</p>
<p>Thank you for the amazing article.</p><p>But i have little problem with serial communication over Arduino serial library. From Atmega i send word &quot;hello&quot; and on computer i get &quot;+&plusmn;&plusmn; ʺ&copy;&Iacute;&euml;&quot;. </p><p>Both device are set on 9600 baud. I use Atmega32, directly connected to computer serial port from pin 14 and 15 (and GND).</p><p>Had someone a similar problem? It is even possible to use Atmel in this way?</p>
<p>At the end of this instructable (end of step 3) is an update about this issue.</p><p>It is about <strong>HardwareSerial.cpp</strong> modification<strong>.<br></strong></p>
<p>actually i have upgraded to windows 10 but this thing does not say that </p>
<p>This article is not intended for your version of the Arduino IDE. When I was writing this article Arduino 1.6.5 not exist at all.</p>
Hello silviius I keep getting errors with my arduino IDE here they are ..........<br>Arduino: 1.6.5 (Windows 8.1), Board: &quot;ATmega32-8mhz&quot;<br><br>Error while burning bootloader.<br><br>java.lang.NullPointerException<br><br> at cc.arduino.packages.uploaders.SerialUploader.burnBootloader(SerialUploader.java:306)<br><br> at processing.app.Editor$59.run(Editor.java:2578)<br><br> at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:311)<br><br> at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:756)<br><br> at java.awt.EventQueue.access$500(EventQueue.java:97)<br><br> at java.awt.EventQueue$3.run(EventQueue.java:709)<br><br> at java.awt.EventQueue$3.run(EventQueue.java:703)<br><br> at java.security.AccessController.doPrivileged(Native Method)<br><br> at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:75)<br><br> at java.awt.EventQueue.dispatchEvent(EventQueue.java:726)<br><br> at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:201)<br><br> at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116)<br><br> at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105)<br><br> at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)<br><br> at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)<br><br> at java.awt.EventDispatchThread.run(EventDispatchThread.java:82)<br><br><br>Does that make any sense ? I dont know why its not working
<p>Arduino: 1.6.5 (Windows 7), Board: &quot;ATmega32-8mhz&quot;<br><br>Selected board depends on 'arduino' core (not installed).<br></p>
<p>You are using 1.6.5.... this solution is for Arduino 1.5.x<br></p><div><p>There are many solutions for Arduino &gt; 1.6.x ... One of them is here:</p><p><a href="https://www.instructables.com/id/ATmega-DIP40-in-Arduino-IDE-164/" rel="nofollow">https://www.instructables.com/id/ATmega-DIP40-in-Ar...</a><br> (this is made by me from scratch... right after 1.6.4 release, mainly <br>for personal use... at that time I have no choice... Since then, there <br>are other solutions available.)</p></div>
<p>Arduino: 1.6.5 (Windows 7), Board: &quot;ATmega32-External 16mhz&quot;<br><br>Selected board depends on 'arduino' core (not installed).<br><br> </p>
<p>Does this work with ATmega32a TQFP....??</p>
<p>It should work. Just be careful with pin mapping... </p><p>For example Arduino Digital Pin0 = PB0 = PIN40 from IC TQFP...</p>
<p>sadly my usbasp programmer isnt recognised in Ubuntu nor in Windows10 (yes installed the driver) maybe I have to make a pony programmer :-(</p>
<p>I'm not sure it will work, but have you tried something like this?</p><p><a href="http://netmaxtech.com/how-to-make/install-usbasp-driver-windows-8-and-windows" rel="nofollow">http://netmaxtech.com/how-to-make/install-usbasp-driver-windows-8-and-windows</a></p><p><a href="https://openchrysalis.wordpress.com/2014/09/26/installing-usbasp-driver-software-in-windows-8-1/" rel="nofollow">https://openchrysalis.wordpress.com/2014/09/26/installing-usbasp-driver-software-in-windows-8-1/</a></p>
<p>yep, tried several. I think including the ones you link to. I did come across some messages though of people who, no matter what, couldnt get the USBasp recognized.<br>In fact both Windows 10 and Ubuntu 12.04 and ubuntu 14.4 indicate the know the device on the USB port... but the applications (IDE and codebender) just dont see it.<br>Thank you nevertheless for trying to help :-)</p>
<p>just let me add that installing the driver in windows 10 was not the problem. That works and I see it in the device manager and windows says it is the most up to date driver, but then the applications dont see it :-)</p>
<p>I wanted to use atmega with 14.7456mhz with arduino ide.</p><p>What changes do i make to the files ?</p>
<p>Try add this to boards.txt (after install other files as in instructable)</p><p>##############################################################</p><p>mega32-14.name=ATmega32-14Mhz<br>mega32-14.upload.tool=avrdude<br>mega32-14.build.mcu=atmega32<br>mega32-14.build.f_cpu=14745600L<br>mega32-14.build.core=arduino:arduino<br>mega32-14.build.variant=mega32<br>mega32-14.upload.maximum_size=32000</p><p>##############################################################</p>
<p>Sorry for the trouble. Had done exactly this. My board isn't working. Worked fine with a new one</p><p>Thank You</p>
<p>pls i want to know how to upload my code to atmega32A after finishing it ana i did your steps correctly</p>
<p>You can upload using any programmer supported in Arduino IDE (like USBasp). Just connect it to your development board. Select board and programmer from Arduino IDE menus.... and press upload button.</p><div>If you have no development board available, you can try to make one...<br>look here for some info/ideas:<br><p>https://www.instructables.com/id/ATmega-DIP40-Minimal-Board/</p></div>
<p>I simulated Arduino sketch in proteus. this works like a charm.</p>
<p>:)</p>
<p>Hello, I am uploading the code over the SPI bus via an Arduino as programmer, but the timing seems to be off on the AT32, whether I use the internal 8mhz or external 16 mhz crystal; and the 16mhz crystal seems worse than the internal 8. Do you know why this is?</p>
<p>Sorry for the late reply. I have the same answer as comment above...</p>
<p>Which comment? I can't seem to find the one you are talking about.</p>

About This Instructable

73,536views

65favorites

License:

More by Silvius:Reading 15 Rotary Encoders with Arduino and ATmega1284 Open Source TV Box - GeekBox AVR Transistor Tester 
Add instructable to: