At this point, Arduino is connected to my ATMega8U DIP on sitting breadboard and it can program it through SPI.
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,
Add https://mcudude.github.io/MiniCore/package_MCUdude_MiniCore_index.json to File -> Preferences -> Additional Board Managers
Install MiniCore boards from Board Manager.
I used the exact same circuit & sketch as the previous attempt with avrdude.
I selected Tools -> Boards -> Minicore -> ATMega8 on Arduino IDE. The port is /dev/ttyACM0.
I selected Tools -> Programmer -> Arduino as ISP.
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,
Am I doing something wrong or Am I missing a step?
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.
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,
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,
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?
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
To be able to upload code over serial.
I think I understand it now. Thank you once again!