Programming an ATMega8

Hi everyone,

I have been searching and searching but I cannot find a straight answer. I have an ATMega8A, an Arduino Uni but no external crystal. I want to program the ATMega8A using the Uno but every example I find uses an external crystal. How can I program the ATMega8A without an external crystal?

A quick look at the ATMega8A datasheet confirms what I suspected; by default it's set up to use the internal 1MHz oscillator, so no external clock source is required. Don't change the CKSEL fuses to use an external oscillator or crystal and you should be fine.

A crystal is not required, just some sort of MCU clock. The details depend on what you use as a programmer, but for the 1 MHz internal RC clock, the ISP programming clock frequency must be set to 250 kHz or lower (1/4 of the MCU clock frequency).

This is by far the best AVR programmer I've ever had the pleasure to use. It works either as an extremely versatile ISP programmer, or serial port interface if you have a bootloader in place.

1 Like

Hi @snolan123. I recommend the use of the excellent 3rd party "MiniCore" boards platform to add support for the ATmega8A to Arduino IDE:

You can install MiniCore via the Arduino IDE Boards Manager:

https://github.com/MCUdude/MiniCore#boards-manager-installation

After installing MiniCore, you can configure Arduino IDE for use with an ATmega8A running on the internal oscillator by the following procedure:

  1. Select Tools > Board > MiniCore > ATmega8 from the Arduino IDE menus.
  2. Select the appropriate clock configuration from Arduino IDE's Tools > Clock menu.
  3. Configure the other submenus of Arduino IDE's "Tools" menu as needed.

As @van_der_decken mentioned, the factory default configuration of the board is running at 1 MHz. You can increase this to 8 MHz if you like. You would do that by the following procedure:

  1. Connect an ISP programmer to the ATmega8.
    You can use your UNO board as a DIY "Arduino as ISP" programmer: https://docs.arduino.cc/built-in-examples/arduino-isp/ArduinoISP/
  2. Select Tools > Clock > Internal 8 MHz from the Arduino IDE menus.
  3. Select the appropriate programmer from Arduino IDE's Tools > Programmer menu.
    If you are using the "Arduino as ISP" programmer, select Tools > Programmer > Arduino as ISP
  4. Select Tools > Burn Bootloader.

In addition to flashing the bootloader binary (which is optional when using MiniCore), the "Burn Bootloader" operation also sets the target microcontroller's configuration fuses according to the configuration from the board definition. So this is why you must perform a "Burn Bootloader" operation after changing the "Clock" configuration:

https://github.com/MCUdude/MiniCore#supported-clock-frequencies

So I did that and I wired it up according to the diagram, tried to burn the bootloader and I get this
Avrdude version 8.0-arduino.1
Copyright see avrdude/AUTHORS at main · avrdudes/avrdude · GitHub

System wide configuration file is C:\Users\snolan\AppData\Local\Arduino15\packages\MiniCore\tools\avrdude\8.0-arduino.1\etc\avrdude.conf

Using port : COM3
Using programmer : stk500v1
Setting baud rate : 19200
AVR part : ATmega8
Programming modes : SPM, ISP, HVPP
Programmer type : STK500
Description : Atmel STK500 v1
HW Version : 2
FW Version : 1.18
Topcard : Unknown
Vtarget : 0.0 V
Varef : 0.0 V
Oscillator : Off
SCK period : 0.0 us
XTAL frequency : 7.372800 MHz

AVR device initialized and ready to accept instructions
Device signature = 00 00 00 (retrying)
Device signature = 00 00 00 (retrying)
Device signature = 00 00 00
Error: invalid device signature
Error: expected signature for ATmega8 is 1E 93 07

  • double check connections and try again, or use -F to carry on regardless

Avrdude done. Thank you.
Failed chip erase: uploading error: exit status 1

OK I'm ashamed to admit it but the chip was not sitting properly. Once I pushed it down I was able to connect and upload a program. It is meant to turn an LED at pin 15 on but it's not working. I've connected ground and power and connected the RESET pin to power. Am I missing something else?

Let's see the program.

// the setup function runs once when you press reset or power the board
void setup() {
  // initialize digital pin LED_BUILTIN as an output.
  pinMode(15, OUTPUT);
}

// the loop function runs over and over again forever
void loop() {
  digitalWrite(15, HIGH);  // turn the LED on (HIGH is the voltage level)
  delay(1000);
  
  digitalWrite(15, LOW);  // turn the LED on (HIGH is the voltage level)
  delay(1000);
}

Cracked it! If I used PIN_PB1 instead of just 15 it works!

Thank you everyone for your help

PIN_PB1 is I/O #9, physical pin #15 on the DIP package.
PIN_PC1 is I/O #15, physical pin #24 on the DIP package.

Your sketch was toggling PC1 on physical pin #24.

I/O#s are not the same as physical pin #s.