Questions about programming ATMega with Arduino

I've been using Arduino as ISP to program some ATMega168's on a breadboard for the past couple days. Somewhat successfully. I've been doing it without a crystal or capacitors, and I assume that is the reason that the IDE gives me "Programmer is not responding" errors most times I try. Sometimes wiggling the chips helps, and of the five I ordered, I couldn't get two to program at all. Is it the lack of crystal causing this?

Also, I'm trying to understand some things about the programming process. Since the chips are set to 8 Mhz internal by default, would it automatically switch to a 16 Mhz crystal without having to change the fuse bits to use an external clock?

Is there any reason I'd need to burn a bootloader if I'm programming them through an Arduino?

I've been using "Arduino as ISP" programmer, but what are the "ArduinoISP" and "ArduinoISP.org" options for?

I saw an article that talked about using the Arduino's clock as the target ATMega's external clock, but I couldn't get it to work. Is this possible?

Having tried this myself & failed (years ago), I can't help with most of your questions.

but re: bootloader --my understanding is this is what literally boots the device, so I think you have to have a bootloader, it doesn't have to be the standard aruduino one though.

and if wiggling helps, that would suggest poor connections. perhaps your breadboard is worn?

That's what I thought, so I soldered a socket onto some protoboard to get some better connections, but still not working great.

can I assume you know what you're doing soldering? Those shouldn't be too hard, but too much heat can damage them. Just checking basics, I never know what people's skill level is.

please clarify what this means. Is it working sometimes (like 1 of 5 attempts), or does it start working & then not finish the flash?

When I was trying this, I recall several youtube tutorials on the subject of shrinking your arduino. which amounted to a standalone atmel328 chip. This was years ago, so I dont remember exactly what was involved, but there were a couple external comps, maybe an oscillator. Have you consulted any of those tutorials?

The ATmegaX68 chips are set to 1 MHz by factory default, 8 MHz internal RC oscillator with the divide by 8 fuse set.

You need to change the fuses to enable the external crystal. Excellent tutorial here: Gammon Forum : Electronics : Microprocessors : How to make an Arduino-compatible minimal board

I think I'm decent. I only hold it on each pin for a couple seconds.

Sometimes it fully programs the chip if I'm pressing down on it into the breadboard really hard for the full duration of the upload. Sometimes not. With and without a socket between the chip and breadboard.

With my new soldered socket, 1 out of 10 attempts working seems about right. And if I get it working then dont touch it, it will continue to work multiple times. Maybe time has something to do with it, because just a couple hours ago I couldn't get it to program, so I left the chip in the socket, then came back just a bit ago and it's been programming fine every time. So I don't dare remove it until I finish writing code for it.

I have not. I was mostly scouring the internet for written tutorials or references to programming them without a crystal.

If I had a chip working, and I accidentally hit an external clock option in the tools menu before hitting upload, does that change the fuses? Or is it just for the IDE to know the current configuration of the target board to program it correctly but not actually changing the clock?

I did read that one. I don't know why I didn't use capacitors like it says, since I think I have two of that value. Maybe that's the issue? I'll try adding them.

I have no idea what "menu" you refer to. Read out the fuses to see what they are set to.

If the fuses are set to external crystal oscillator, you don't actually need a crystal for programming. Supply an external clock to one of the crystal pins, as described in Gammon's tutorial.

Capacitors of the appropriate value are absolutely required for reliable operation of a crystal oscillator, although a breadboard circuit might accidentally function without them, if the stray board and wiring capacitances are high enough.

I recommend that you don't use an external oscillator, at least while you're exercising. Making a high-quality circuit using capacitors is not so easy, and if you change the fuses and the crystal does not start, it will be more difficult to return back.

Actually, breadboarding a crystal oscillator with caps works fine. The oscillator circuitry on ATmega chips is very forgiving and Gammon's tutorial has worked for countless people. And he explains how to supply a clock signal if you get stuck. Easy!

The Tools menu of the Arduino IDE. With an Atmega168 selected from Boards, it gives options for Clock and BOD.

I tried that, but I think the sketch from the tutorial is made for an Atmega328. I think I remember my Atmega168 not having room for it.

For what? The ATmega168 does work with Gammon's tutorial. I've used it to program such chips several times without problems.

However, I strongly recommend Pololu's AVR ISP programmer v2.1 for everything AVR related. Cheap, extremely flexible and utterly reliable. Pololu USB AVR Programmer v2.1

Good luck with your project!

After having gone through this many times it's really not difficult. But not for a beginner. I remember the first time I spent a lot of time... :slight_smile:

I thought I got an error about the "Atmega_Board_Detector" sketch being too big, but maybe not. I'm going to go through the tutorial again and see if I can get it working.

Thank you for the recommendation, I may do that.

This sketch does not need to be uploaded to atmega168, it is uploaded to another arduino, which is used as a programmer

Oh i see, whoops.

Many beginners pay attention and are successful. Others do not.

1 Like

I followed the tutorial, I think to a tee, but still running into problems. When running the Board Programmer sketch, I get various errors. With one chip, I get this:

Atmega chip programmer.
Written by Nick Gammon.
Version 1.38
Compiled on Jul 18 2022 at 20:35:18 with Arduino IDE 10819.
Attempting to enter ICSP programming mode ....
Entered programming mode OK.
Signature = 0x01 0x01 0x03
Unrecogized signature.
LFuse = 0xFF
HFuse = 0x01
EFuse = 0xFF
Lock byte = 0xFF
Clock calibration = 0x01
Programming mode off.
Type 'C' when ready to continue with another chip ...

With two others, it seems to recognize the chip, but says there is no bootloader support:

Attempting to enter ICSP programming mode ...
Entered programming mode OK.
Signature = 0x1E 0x94 0x06
Processor = ATmega168V
Flash memory size = 16384 bytes.
LFuse = 0xE2
HFuse = 0xDF
EFuse = 0xF9
Lock byte = 0xFF
Clock calibration = 0x87
No bootloader support for this device.
Programming mode off.
Type 'C' when ready to continue with another chip ...

Attempting to enter ICSP programming mode ...
Entered programming mode OK.
Signature = 0x1E 0x94 0x06
Processor = ATmega168V
Flash memory size = 16384 bytes.
LFuse = 0x62
HFuse = 0xDF
EFuse = 0xF9
Lock byte = 0xFF
Clock calibration = 0x96
No bootloader support for this device.
Programming mode off.
Type 'C' when ready to continue with another chip ...

And the last chip just says programming failed.

These are Atmega168-20PU, so I'm not sure where Atmega168V is coming from.

Probably not, if you got them from a reseller like Amazon, eBay, Alibaba, etc. More likely you have relabeled factory rejects or counterfeit parts.

The ATmega168V is a different beast and appears to be obsolete. Microchip does not even list them in its product catalog.

Oh ok. Yeah I got them on eBay from a Chinese seller. I'm currently looking at Mouser to order some from a more reputable source. They have Atmega168V-10PU, Atmega168P-20PU, and Atmega168PV-10PU. All the Atmega328's are out of stock. I guess I should go with the 168P?