How to program blank avr

Hi,

I'm working on a PCB project using an Atmega324P, TQFP44. I want to be able to program this after it has been assembled by my PCB manufacturer. I am using atmel studio, and not the arduino libraries.

I am thinking of adding header pins to the PCB that connects to the required pins to program the device.

But I'm a bit confused with how you actually program the chip. I see lots of videos with different USB to serial adapter and different avr programmers.

I bought some an Atmega324PA PDIP and a USB to serial adapter from ebay, but I can't seem to get it to work. Do I need an avr programmer from Atmel to do this? But which one?

Thanks.

I am using atmel studio, and not the arduino libraries.

If your not using Arduino your asking in the wrong forum.

but heres an arduino link that should answer some of your questions.

Installing an Arduino Bootloader

[u]Burning sketches to the Arduino board with an external programmer[/u]

I see lots of videos with different USB to serial adapter and different avr programmers.

I bought some an Atmega324PA PDIP and a USB to serial adapter from ebay,

Of course, the regular serial port won't work until the chip is programmed. :wink: The Arduino comes with the bootloader pre-loaded, so the serial/USB port works out-of-the-box.

Most modern microprocessor-based products are in-circuit programed with a special programmer. (starting with a blank chip).

But IMO, the bootloader is one of the best things about the Arduino... You just plug it into your USB port and it's ready to go.. No programmer needed! If I buy a different microcontroller I'll have to buy (or build) a programmer and I'll have to buy a development board. ...If you are "going into production", those are small additional development costs. As a hobbyist building a one-off project, it's nice to avoid those expenses.

The way to program a blank AVR chip is with In-Circuit Serial Programming (ICSP). You use a special "ISP" device to write directly into the FLASH memory of the chip. One inexpensive choice is the "USBasp" which you can buy through ebay for about $4. The normal ICSP connection is a 10-pin (2x5) pin header. The "USBasp" has a matching 10-pin connector and cable. The Arduino saves space by eliminating 4 of the 5 Ground wires and using a 6-pin (2x3) pin header. An adapter to connect the 10-pin cable to an Arduino 6-pin header is typically sold separately for about $2. Design your board with either a 10-pin or a 6-pin ICSP connector.

I also like the USBasp, though I haven't worked much with Atmel Studio. If you prefer the 6 pin connector, you can save some money and improve usability by buying a 6 pin USBasp. They're a bit less common and sometimes slightly more expensive than the 10 pin model but you'll find them on eBay with just a bit of searching.

I took a Pro Mini, wired it up as ISP programmer (no headers except for the FTDI one, ISP wires soldered into the holes instead), and use that for programming ATtinys. Should work just the same with ATmega chips.

If producing PCBs you can ask the manufacturer to program them for you - just the bootloader, or your complete sketch.

Thanks for all the replies!

So if I understand it correctly:

  1. When uploading a program to the AVR through atmel studio with an avr programmer, it will also upload some kind of bootloader. But does this bootloader allow you to upload a new program using only the RX and TX pin with a FTDI/PL2303 adapter, like you can with the arduino?

  2. If you have uploaded a program using an AVR programmer, can you use MISO, MOSI, RST, SCK as normal IO for other purposes, and you will still be able to reprogram it later?

jgrovan:
When uploading a program to the AVR through atmel studio with an avr programmer, it will also upload some kind of bootloader.

No. In fact, when you upload a program using an ISP programmer it will generally overwrite the bootloader.

jgrovan:
But does this bootloader allow you to upload a new program using only the RX and TX pin with a FTDI/PL2303 adapter, like you can with the arduino?

It depends on the bootloader. The standard Optiboot bootloader will do that for you.

jgrovan:
2. If you have uploaded a program using an AVR programmer, can you use MISO, MOSI, RST, SCK as normal IO for other purposes, and you will still be able to reprogram it later?

Yes.

jgrovan:
2. If you have uploaded a program using an AVR programmer, can you use MISO, MOSI, RST, SCK as normal IO for other purposes, and you will still be able to reprogram it later?

Depends somewhat on what's connected to it.

SPI slaves should set their connections to high impedance state when not in use, and SPI lines are driven high and low. So as long as you use those pins for SPI only, no problem. If you use it for other things, there may be issues.

wvmarle:
Depends somewhat on what's connected to it.

SPI slaves should set their connections to high impedance state when not in use, and SPI lines are driven high and low. So as long as you use those pins for SPI only, no problem. If you use it for other things, there may be issues.

Hi,

Reset will have a pull-up resistors and a 0.1uF connected to it, as I've seen people suggest. MOSI, MISO and CLK will be connected to an IDC connector, so I can just unplug that when programming. I could probably even use that IDC connector and wire it as I want, to program it, to avoid adding header pins for programming :slight_smile: All 5V, GND, MOSI, MISO, RST, CLK will be wired through that IDC connector to a different PCB.

This should work, I suppose?

I ignored reset as it's a special pin that normally only has reset-related stuff connected to it. You can of course set the reset as normal I/O pin but then you have to use a 12V pulse or so to program the thing.

For reset normally a pull-up resistor to Vcc is enough. Don't think I've ever seen an additional cap on that one, other than to intentionally disable it.

wvmarle:
I ignored reset as it’s a special pin that normally only has reset-related stuff connected to it. You can of course set the reset as normal I/O pin but then you have to use a 12V pulse or so to program the thing.

For reset normally a pull-up resistor to Vcc is enough. Don’t think I’ve ever seen an additional cap on that one, other than to intentionally disable it.

For atmega 324,the reset is not possible to configure as IO anyway.

Does the avr programmer actually need the reset to be able to program it? My intension is to completely disable the reset.

Quite sure it’s needed, if only to provide a means of telling the chip it’s got to start listening for new code to be uploaded.