Maker Pro
Maker Pro

Programming Atmega 328

Blue_fog

Nov 30, 2011
17
Joined
Nov 30, 2011
Messages
17
Hi,

I am new to the micro controller world and want to start learning stuff. I want to program an Atmega 328 on a breadboard. I have made the power circuit on it and have a "clean" 5V supply on it for the MCU to work. Now I want to know an easy way to be able to program it from my desktop. I have been searching things out for the past couple of days but nothing is making any sense to me. I am confused about connecting the chip to my PC.

Preferably, I want to do it on a USB port but most of the tutorials out there suggest using serial. I read about the MAX232 IC and related things. But I want to do things with USB. So I noticed something about the FTDI chip. Please tell me an easy way to program the MCU that's not all readymade (ie. I want to learn something out of this interfacing thing.)

Thank you in anticipation.

:)
 

Harald Kapp

Moderator
Moderator
Nov 17, 2011
13,728
Joined
Nov 17, 2011
Messages
13,728
The ATMegas are not per se programmable via USB. You can buy USB in-circuit programmers for ATMegas (just Google). Or you can build your own.
 

(*steve*)

¡sǝpodᴉʇuɐ ǝɥʇ ɹɐǝɥd
Moderator
Jan 21, 2010
25,510
Joined
Jan 21, 2010
Messages
25,510
You can but a USBTinyASP for under $5 delivered.

Another option is a usb to serial port. This will work if the arduino has the bootloader installed.

A serial programmer is generally a real pain in the bottom to get working. (and you can't program the bootloader with it.

If you have an arduino, you can load the app which turns the arduino into a programmer for these chips. This will allow you to bun a bootloader, after which things are a lot easier.
 

robertgzzzt

Jun 26, 2013
98
Joined
Jun 26, 2013
Messages
98
Hi Bluefog, welcome to the forum. I am also very new to the world of micro-controllers, but I have managed to program a sketch onto a standalone ATMega328 chip (with bootloader pre-installed) on a breadboard.

1. You need to tell us what Arduino hardware you own aside from just the Atmega328 chip.

2. You did not mention whether or not your chip already has the bootloader installed on it. This is very important.

I can give you links to some reference material, but without knowing hardware you already have it's difficult to get into specifics. At any rate, this is the way I did it.

First, I bought one of these. (note: this product does not include the breadboard)
http://www.amazon.com/Virtuabotix-B...UTF8&qid=1389341218&sr=8-1&keywords=bareduino

Then, after I assembled it on my breadboard, using these instructions.....
https://www.virtuabotix.com/product-bareduino328-barebones-microcontroller-guide/

I followed this guide to program it with a working sketch....
https://www.virtuabotix.com/bareduino328-programming-guide/

I used an Arduino Uno R3 to program my ATMega328, but you can also use this USB Serial Adapter, it is explained in the programming tutorial I linked you to above.
http://www.amazon.com/Arduino-USB-Serial-Light-Adapter/dp/B007BI5I4W

If your ATMega328 chip has no bootloader pre-installed, then you'll have to install the bootloader before you can program the chip with a working sketch.

I hope this helps...
 

Blue_fog

Nov 30, 2011
17
Joined
Nov 30, 2011
Messages
17
Hi Bluefog, welcome to the forum. I am also very new to the world of micro-controllers, but I have managed to program a sketch onto a standalone ATMega328 chip (with bootloader pre-installed) on a breadboard.

1. You need to tell us what Arduino hardware you own aside from just the Atmega328 chip.

2. You did not mention whether or not your chip already has the bootloader installed on it. This is very important.

I can give you links to some reference material, but without knowing hardware you already have it's difficult to get into specifics. At any rate, this is the way I did it.

First, I bought one of these. (note: this product does not include the breadboard)
http://www.amazon.com/Virtuabotix-B...UTF8&qid=1389341218&sr=8-1&keywords=bareduino

Then, after I assembled it on my breadboard, using these instructions.....
https://www.virtuabotix.com/product-bareduino328-barebones-microcontroller-guide/

I followed this guide to program it with a working sketch....
https://www.virtuabotix.com/bareduino328-programming-guide/

I used an Arduino Uno R3 to program my ATMega328, but you can also use this USB Serial Adapter, it is explained in the programming tutorial I linked you to above.
http://www.amazon.com/Arduino-USB-Serial-Light-Adapter/dp/B007BI5I4W

If your ATMega328 chip has no bootloader pre-installed, then you'll have to install the bootloader before you can program the chip with a working sketch.

I hope this helps...

I have working experience with the Arduino, but currently I do not have it available(ie. i do not have an arduino right now0). Isn't there any way I can program this chip without the arduino? I am looking at various programmers and things like that. Is the MAX232 IC enough for interfacing the uC to the computer?

@Steve I do not have an arduino.. Should have mentioned that in the first post!

I purposefully do not want to use Arduino here. I want to get to the complexities of the uC world!

I was following this tutorial : https://www.sparkfun.com/tutorials/93

Thanks for the replies!

:)
 
Last edited:

robertgzzzt

Jun 26, 2013
98
Joined
Jun 26, 2013
Messages
98
Isn't there any way I can program this chip without the arduino?


yes, you can, but how you go about it will depend on a couple of things.

1. The type of ATMega328 you have (there's more than one). Just post what's printed on the back of the chip.

2. Whether or not the chip already has a bootloader installed on it, and if it does, is it the Duemilanove bootloader or the UNO bootloader?

I purposefully do not want to use Arduino here. I want to get to the complexities of the uC world!

I don't understand what you mean. You're going to have to use something to interface your computer with your chip on the breadboard. If you have access to an Arduino, it doesn't make any sense not to use it.
 
Last edited:

(*steve*)

¡sǝpodᴉʇuɐ ǝɥʇ ɹɐǝɥd
Moderator
Jan 21, 2010
25,510
Joined
Jan 21, 2010
Messages
25,510
My understanding (from some experience) is that there are three ways to program an ATMega328 chip (and these apply pretty much to the entire range of chips)

1) high voltage serial/parallel) programming
2) low voltage "in-circuit" serial programming
3) programming via a bootloader.

High voltage programming

This is the "best" way to program an AVR chip. All of them support it, it can be done very quickly, and you can do it even if you have stuffed up the "fuse bits" so that programming via other methods is not possible.

However, almost no hobbyist uses this.

See here for more information.

Low voltage (in-circuit) serial programming

This is probably the most popular way of programming bootloaders to ATMega chips.

It is possible to program the part in such a way that you can't use this method to program it again. (See here). You need to take care if you're changing the "fuse" settings for a special bootloader or for programming where you're not using a bootloader.

This method of programming allows you to program the chip so that it used the internal RC oscillator (so you don't need a crystal). I rarely use an ATMega chip with a crystal any more. It makes bare-bones use of the device much easier.

This is usually done using the 6 pin ICSP header that you find hidden on many Arduino boards, and built in to any project I make (well, *you* don't see those). Here is an example of a tiny programmer made using this method.

You'll find plenty of tutorials for this and many of them look like this. However they are not what one would call minimalist.

My preferred method is here. This isn't the one I normally point to (my Google-fu is failing me) but it illustrates the idea. What is important here is that you'll be using non-standard (at least non-standard for an arduino) boot loaders and fuse settings so you can get away without a crystal.

Here are the more official instructions, which concentrate on programming the device from another arduino, but really they're just using the equivalent of the 6 pin header and using the arduino as a "cheap" ICP device. "Cheap" means you probably have it so you don't have to buy one -- cheap in time.

So, practically, I use one of these. Note that it has a 10 pin header. Some have 6 pin headers built in (like this). However, I find it generally more convenient to use an adapter like this.

Oh, and they provide power as well.

They tool a while to arrive when I ordered them the first time, so I used an arduino as the programmer. If you do this (using the sample code in the arduino environment -- I use Arduino ERW -- then you may have to wire in an extra resistor to prevent the board resetting while you use it this way.

If you go down this route you'll need settings in the environment, bootloaders, and fuse settings. I think the links will provide eough info, but if you go down this route, contact me and I'll give you a place to start. It will save you a lot of effort.

Programming via a bootloader

This is what the vast bulk of arduino board users use. When it boils down, it is programming via RS232. The board may have a 5 or 6 pin (in a single line) header, or it may have a serial port (which is essentially the same thing), or it may have a USB interface. The usb interface uses a usb to serial chip, so it's again, just another way of using RS232.

Once you've programmed a bootloader, you can use this method.

Look for an FT232L board. They can be really cheap.

The only differences between the various bootloader methods is resetting and power.

Plain RS232 won't provide power to the board, and may not auto-reset.

5 pin headers provide power, but not auto-reset (and they're rare). 6 pin headers provide auto-reset.

The FT232 boards typically have a 6 pin interface.

These sound great, but they're not as useful as the in-circuit programming.

Oh, and be aware that the 6 pin header for serial programming via a bootloader has nothing in common with the 6 pin header for in-circuit programming.

Also, for any programming method which provides power, you may need to design your board so it doesn't try to run high power peripherals if the board is powered from the programming interface. I generally do this using a schottky diode between the main power rail and the arduino power pins so ICSP power (or indeed power from the serial programming connector) cannot feed back to power other things, but this method may not work for you.
 

Blue_fog

Nov 30, 2011
17
Joined
Nov 30, 2011
Messages
17

(*steve*)

¡sǝpodᴉʇuɐ ǝɥʇ ɹɐǝɥd
Moderator
Jan 21, 2010
25,510
Joined
Jan 21, 2010
Messages
25,510
OK, bear in mind what I said about the serial method being a potential headache to get running...

I would probably go with the seller offering a choice of bootloaders. If one works and the other doesn't then you can program the one which doesn't from the one which does :)
 

Blue_fog

Nov 30, 2011
17
Joined
Nov 30, 2011
Messages
17
Since I am using a chip with the Arduino bootloader would I also have to get an external crystal for the chip to run?
 

(*steve*)

¡sǝpodᴉʇuɐ ǝɥʇ ɹɐǝɥd
Moderator
Jan 21, 2010
25,510
Joined
Jan 21, 2010
Messages
25,510
yep, and the capacitors.
 
Top