Unknown Response when using Uno Rev3 as an ISP for burning hex on Atmega8

Hi Everyone! I wrote a small blink program for an ATMega8U-DIP I bought recently. The source is this,

#ifndef F_CPU
#define F_CPU 16000000
#endif

#include <avr/io.h>
#include <util/delay.h>

int main(void) {

  DDRB |= (1 << PB0); // Set PB0 as output
  while(1) {
    PORTB ^= (1 << PB0); // Set PB0 high
    _delay_ms(500);       // Small delay
  }
}

Here are the steps I followed,

  1. I compiled the above code to main.hex using avr-gcc and avr-objcopy.
  2. I connected my Arduino UNO Rev3 and uploaded the Examples -> 11. Arduino ISP sketch onto my board.
  3. I disconnected my uno board and connected all the wires according to this schematic,

At this point, Arduino is connected to my ATMega8U DIP on sitting breadboard and it can program it through SPI.

  1. I then tried to upload my main.hex file I compiled earlier via avrdude -c arduino -p m8 -P /dev/ttyACM0 -b 19200 -U flash:w:main.hex but I get this response,
avrdude error: protocol expects OK byte 0x10 but got 0x14

avrdude error: protocol expects sync byte 0x14 but got 0x01
avrdude error: protocol expects sync byte 0x14 but got 0x10
avrdude error: initialization failed, rc=-1
        - double check the connections and try again
        - use -B to set lower ISP clock frequency, e.g. -B 125kHz
        - use -F to override this check

avrdude error: unknown response=0x12

avrdude done.  Thank you.

Another thing I tried was to burn Minicore ATMega8 bootloader onto my ATMega8 through Arduino IDE itself with the following steps,

  1. Add https://mcudude.github.io/MiniCore/package_MCUdude_MiniCore_index.json to File -> Preferences -> Additional Board Managers
  2. Install MiniCore boards from Board Manager.
  3. I used the exact same circuit & sketch as the previous attempt with avrdude.
  4. I selected Tools -> Boards -> Minicore -> ATMega8 on Arduino IDE. The port is /dev/ttyACM0.
  5. I selected Tools -> Programmer -> Arduino as ISP.
  6. I then clicked on Tools -> Burn bootloader but I got this error in IDE output,
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
Failed chip erase: uploading error: exit status 1

I have two questions,

  1. Am I doing something wrong or Am I missing a step?
  2. How do I get the AVR code I've compiled onto my ATMega8 sitting on breadboard with Arduino acting as an ISP?

You have D10 on the Arduino connected to the wrong side of the reset resistor on your target. It should go direct to the reset pin, with the 10k resistor acting as a pullup.

1 Like

This is the new schematic,

The uno rev3 is runing the Examples -> 11. Arduino ISP sketch and I still the get the same errors when I click "Burn Bootloader" even after the D10 change,

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
Failed chip erase: uploading error: exit status 1

Here's the screenshot of IDE and the options I've selected,

e

Trying this with avrdude results in,

➜  avr-test git:(master) ✗ avrdude -c arduino -p m8 -P /dev/ttyACM0 -b 19200 -U flash:w:main.hex


avrdude error: protocol expects OK byte 0x10 but got 0x14

avrdude error: protocol expects sync byte 0x14 but got 0x01
avrdude error: protocol expects sync byte 0x14 but got 0x10
avrdude error: initialization failed, rc=-1
        - double check the connections and try again
        - use -B to set lower ISP clock frequency, e.g. -B 125kHz
        - use -F to override this check

avrdude error: unknown response=0x12

avrdude done.  Thank you.

Update: I retried all the pins and I can burn the bootloader now via Tools -> Burn Bootloader option. I think it was the pins. I still can't do it via avrdude CLI as I'm don't what command Arduino IDE executes for burning bootloader to my ATMega8 flash.

Before I close this, Can you tell me how I can get the C code I wrote onto the ATMega8 mcu after the MiniCore ATMega8 bootloader burn stage? I don't really have any adapters (FTDI, USBASP etc.) lying around so is it possible to do just via my Uno Rev3 board acting as ISP once again (in a similar process to earlier)? I've already compiled the code below to main.hex,

#ifndef F_CPU
#define F_CPU 16000000
#endif

#include <avr/io.h>
#include <util/delay.h>

void toggle_led() {
  // enable PB0 (14) as output
  DDRB |= (1 << PB0);
  while(1) {
    // switch between high low
    PORTB ^= (1 << PB0);
    _delay_ms(500);
  }
}

int main(void) {
  toggle_led();
  return 0;
}

Enable verbose output during upload under File → Preferences; you will see the exact command that is issued for the burning of the boot loader.

You can use the menu Sketch → Upload Using Programmer and use the programmer.

1 Like

Thank you so much! I was able to flash my code by erasing the mcu and then flashing my hex file by copying the custom commands ran by IDE. It works & the led blinks! May I ask you how do I know if I need a bootloader to run my compiled hex code?

You don't need a boot loader. There are two reasons for burning the boot loader

  1. It's an easy way to set the fuses. But you can do that "manually" as well.
  2. To be able to upload code over serial.
  1. It's an easy way to set the fuses. But you can do that "manually" as well.

How do one know what fuse they have to set? I can see there are couple of actions one can perform which I think might have their own fuses. Actions such as erasing flash, eeprom and writing to them. Do you know a place where can I read more about these fuses especially the one's related to actions on my microcontroller (i.e. an atmega8a)?

For example, this is the avrdude command I ran for erasing flash that includes fuses: avrdude -v -p atmega8 -c stk500v1 -P /dev/ttyACM0 -b 19200 -e -U lock:w:0xff:m -U efuse:w:{bootloader.extended_fuses}:m -U hfuse:w:0b11000111:m -U lfuse:w:0b10111111:m

I then used this one to write my main.hex which also includes fuses: avrdude -v -p atmega8 -c stk500v1 -P /dev/ttyACM0 -b 19200 -U flash:w:main.hex:i -U lock:w:0xff:m

  1. To be able to upload code over serial.

I think I understand it now. Thank you once again!

The datasheet of the microcontroller.

1 Like

This is a useful tool when working directly with fuses:

1 Like

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.