NerdKits - electronics education for a digital generation

You are not logged in. [log in]

NEW: Learning electronics? Ask your questions on the new Electronics Questions & Answers site hosted by CircuitLab.

Microcontroller Programming » How to load hex file to ATMega?

February 24, 2014
by boxvic
boxvic's Avatar

Hi all,

I know next to nothing about C programming, so my NerdKit has sat basically unused for a couple of years. I do however know relay/ladder logic- it's part of my job. I recently wanted to get back into tinkering with stuff and found an excellent compiler software that lets you create hex files for certain ATMega and PIC chips in ladder logic. It has a similar interface to old Toyopuc software. Problem is this software compiles a hex file and I don't know what to do with it. When I first got my kit I remember doing some basic C stuff in WinAVR and then creating make and hex files, but I'm clueless on how to use just a straight hex file.

February 25, 2014
by Rick_S
Rick_S's Avatar

Do you still have the downloads that you got with your kit? If not, you can go to the members area and download the users guide and code samples. In the code samples, you'll find folders for the various projects in the guide. There is a "makefile" for each. With minor editing, you will be able to modify the file to upload to the chip.

The current version of the AVR-GCC toolchain can be downloaded from Atmel's site Here.

I'm not sure if it has AVRDUDE (the software to upload to the chip) or not. If not, you can get a recent version by downloading and installing the arduino software.

Hope that get's you started,

Rick

February 25, 2014
by boxvic
boxvic's Avatar

I've still got the nerkits folder with all of the code in it. What changes would need to be made to the make file?

February 26, 2014
by Rick_S
Rick_S's Avatar

If all the NK software is still installed, you should still have avrdude on your computer.

These steps will transfer that hex file to your micro-controller.

First make sure you setup your programming cable and microcontroller as described in your NK guide. This will get the hardware setup and ready to transfer.

Create a new folder in the root directory (Upper most level or C:\ on most PC's) of your hard drive and place your hex file in it. For this discussion, name the folder upload. So you now should have a C:\upload\ folder with your hex file in it.

Shell out to the command prompt (Windows start menu - select run - type cmd.exe press enter.

Type "CD \upload" without the quotes then press enter

The prompt at the left of your screen should change to C:\upload> indicating you are in the folder.

Now type "avrdude -c avr109 -p m168 -b 115200 -P COMxx -U flash:w:hhhh.hex:a" again without the quotes, replacing the xx in COMxx with the communications port your serial adapter is in (COM1, COM2, etc...) and replacing hhhh with the file name of your hex file. Then press enter. Again, consult your Nerdkit Guide to see how to determine your COM port number.

If it goes correctly, you should see some uploading info go on your screen then it should state it's success.

Good luck

February 26, 2014
by boxvic
boxvic's Avatar

Thanks for the help! I got the file to load to the controller, but it doesn't do anything. I can use your command line method to load the NK files and they work just fine. So I guess that compiler isn't as great as I thought.

It doesn't have an option to compile for an ATMega168, just an ATMega8. That might be the problem. I was hoping it would still work since I think everything is the same between them except memory size, but apparently not.

February 26, 2014
by Noter
Noter's Avatar

Different mcu's can have hardware registers in different locations and sometimes different formats for port configurations with even more differences possible for peripheral devices.

PLC's are ancient technology anyway so now is a good time to start learning C. There are many tutorials online and don't forget to check youtube for video training clips. And buy a few good books on C to keep handy. Take the time to learn C and micro-controller programming and have some fun!

February 27, 2014
by Rick_S
Rick_S's Avatar

ATMega88 is more like the 168 in the kit. The ATMega8 is a generation earlier as I recall.

Post a Reply

Please log in to post a reply.

Did you know that one NerdKits customer discovered that his hamster ran several miles in a night using his kit and a Hall-effect sensor? Learn more...