¿ªÔÆÌåÓý

ctrl + shift + ? for shortcuts
© 2025 Groups.io

Re: Programming the Atmega238P


 

¿ªÔÆÌåÓý

Phil,

As has been suggested there are a ton of youtube videos and other web pages telling you how to program an AVR (the ATMega328P computer chip sold by Atmel/MicroChip used on Arduino boards) . This is just one of those pages (if you have an Instructables.com? account):



The easiest way is to buy a Arduino Uno (or 2 or 3) and a proto board.? Also load the Arduino IDE (the Windows or Linux program you load on your computer to program AVR chips and boards).? Hook up your Uno (with the programmer you just built on that proto board) and then go to "Files" in the IDE menu and select "Examples" and load the AVR ISP example and upload it to your Uno.? Once you do that then you just made that Uno into a AVR programmer so it will pass your code on through to the chip you have in the proto programmer.? Now you will have had to set the IDE up to know the board is the Arduino Uno and know which comm port (usb picks many virtual comm ports so it is not always the same number) before you could do this.?? Now under "Tools" on the IDE menu (where you checked and set up the Board and the Port) under the "Programmer:" section pick Arduino as ISP.? The when you compile and upload your INO source code (your code you want to upload is a INO isn't it?).? Then under "Sketch" menu heading either pick "Upload using Programmer" or Ctl Shift U or hold shift key down and click on the arrow pointing right located just below the menu bar and that sends your compiled code to the Uno which then passes it on to the target chip in the programmer on the proto board.? I would suggest using a 28 pin narrow dip (0.3" spacing between rows that matches the ATMega328P) on the proto board.

Personally I like the AVR ISP boards like this one:



?I bought several on ebay and when I got them they were about $2 each but think they are up to about $6 (delivered) now.? Anyway that just plugs onto the top of the Uno and eliminates the need to make a proto board programmer (like the Instructables page did).? With that all said,? it also means that you have to have a ATMega328P or other DIP (dual inline package) AVR IC that you are programming.? Either that or you have bought one of the adapter sockets that are say QFN32 (the smt version of the ATMega328P but in smt format) to Dip sockets (not cheap) sold for the TL866 and similar programmers.? Programmers like the TL866 use a Hex file (not an INO) so your INO file has to be "exported" and grab the hex file it made. That hex file from the IDE always makes 2 versions in the IDE.? One is the bare INO and the second is the INO PLUS THE BOOTLOADER both in Intel Hex format.

Speaking of Bootloader,? there are some things to keep in mind. First,? if you buy a bare ATmega328P say from Digikey or Mouser and not the "Arduino chip" or you buy one on Ebay/Amazon then you will have to do one of two things.? The one thing is to upload the Bootloader to the chip.? If that has never been done then it means the fuses were never set.? The important one to me is the one that tells the chip to look for either the onboard 8mhz clock or an external (crystal) clock. Ask me how I know!? You can also burn the bootloader to the chip just using the Arduino IDE by going to the menu and again under "Tools" and at the bottom select "Burn Bootloader." The bootloader only needs to be loaded once (because it sets the fuses) at the start.? If you load your hex file or compiled INO file and then decide to load the bootloader then it will overwrite and erase your sketch so you will have to load that again.

That second thing I mention is that you can use the bare AVRDude (the program that the IDE actually uses to do all the work) or in my case AVRDUDESS (the AVRDUDE gui)to set those fuses you want.? In MOST CASES you do not have to load the bootloader first (or at all) if you have set the fuses.? Be sure not to set the lock fuse though as you may not be able to ever program that chip again. AVRDude is the backend that the Arduino IDE uses to program your chip or your Arduino (Uno, Mega, Nano, etc).? You can just call the AVRDude to do things as you do not have to load the IDE. There are many things that the IDE will not do but can be done with AVRDude (or AVRDUDESS) and one is to read an existing chip (assuming the lock bit was not set).? You can do it with AVRDude but can not use the IDE to do it.? There are many other things that the IDE will not do that AVRDude can do (with the right command line command).

Before I figured out that my particular application did not require the bootloader if I set the fuses (at least the one oscillator fuse) I bought a product from Canaduino which is a stand alone bootloader loader like this one:


It cost about $16 delivered from Canada but I think it is just a refined version of the STandalone programmer that ADafruit sells.? Anyway it needs usb (for power only) and put your ATMega328P (dip) in the ZIF socket and hit program and 6 seconds later the fuses are set and bootloader is loaded. Because the Canaduino board now uses the smt version of the ATMega328P it is no longer a kit but a finished board (no enclosure but none really needed).

Be aware that some sketches will overwrite the bootloader if the bootloader was loaded.? On Arduino.cc forum it says IT WILL Overwrite but that is an exaggeration as it does not necessarily do that but if the sketch is too big it will. Even if that bootloader does get overwritten you do not have to reload the bootloader (normally) again.

Someone mentioned buying Uno clones.? They are not clones. Arduino is open source so anyone can make and sell them. What they can not do is use the Arduino logo on the boards.? Also be very aware that most (if not all) current version Uno's sold now use the 32 pin smt version of the ATMega328 so you can not easily remove and replace the chip with a dip version but with the programmers above you do not need to. The fact that they are now mostly smt version makes it hard to try your sketch and troubleshoot it since you can't just plug your newly programmed chip into the Arduino UNO in place of the stock chip to find out if it worked.

I have never figured out why Atmel/MicroChip made the smt version of the ATMega328P which is a 28 pin dip but the smt version has 32 pins.? Go figure!? But then I found out the hard way that their ATMega16U and ATMega32U are not even in the same family of chips with the ATMega16U2 (and 4) and ATMega32U2 (and 4)!? My TL866 will program ATmeaga16U and 32U ships but not the 16U2 or 4 or the 32U2 or 4!? It will burn them up (ask me how I know).

With all that said,? you did not say what your code is that you want to upload.? Is it an INO sketch or is it a Hex file?

I hope this is helpful and not confusing.

Good luck.

Jim Pruitt
WA7DUY




On 10/29/2021 10:30 PM, Wayde Nie via groups.io wrote:

The best thing about the atmel microcontrollers is that there's so many ways to work with them! The worst thing about the atmel microcontrollers is that there's so many ways to work with them!!! :-) Where to start?

The easiest way ,I think, might be to get an Arduino uno or clone uno board with the socketed Atmega238P chip. You can program it and debug with the Arduino IDE and use it as is, or pop the chip out and use it bare in your other circuits. (some modes need a crystal, but stick to the internal resonator modes to start, just to make it easier)

If you get additional 328p's for the board you might want to start with chips with the Arduino bootloader already on them as they are a drop in replacement on an Uno with a socket. (Some sellers are better than others at reliably indicating if they preload the bootloader, depending on the source...)

But... Buy 2 Arduino uno boards, and one can be loaded with an in circuit serial programing (ICSP) program (an example script distributed with the Arduino IDE) and use it to program bare atmega chips, either with the bootloader (making them useable to load your scripts from within the ide), or your just loading your own scripts directly... (The bootloader code is bundled in with the ide)

There are dedicated ICSP programmers too, but a lot of them amongst hobby community are themselves just atmega based boards... Another uno board works just as well imo, and can do double duty as another Arduino dev board...

There's a series of YouTube videos from a channel called "wifi sheep" where he's making an atmega tiny basic computer, but in the series he modifies an Arduino Uno socketed board with a zif socket so he can swap chips easier as he programs them. Along the way he outlines a decent foundational method of getting started with these chips that you could build on from there... Ymmv , of course :-)

Good luck! They really are a lot of fun!

Wayde Nie VA3NCA
73


-------- Original message --------
From: "wa8yan.radio via groups.io" <wa8yan.radio@...>
Date: 2021-10-30 00:44 (GMT-05:00)
Subject: [QRPLabs] Programming the Atmega238P

Can one of you who do this all the time advise me what minimal hardware and software is needed to do simple programming of the Atmega chip.? I already have the script I want to put in it, my main interest is just to familiarize myself with the basics with a small project and to get a useable chip out of it.

Perhaps a reference to a good beginning (very beginning) tutorial.? Everything I've seen so far assumes way to much about what I already know.? They begin with acronyms and processes that are meaningless to me. Little wonder I haven't learned much yet.? There has to be someone who can teach someone like me who hasn't kept up with the pace of progress, but have a foundation in the rudiments.

73 Phil WA8YAN


Join [email protected] to automatically receive all group messages.