How to burn bootloader on Atmega8?

I have bare Atmega8 with fuses to factory defauls (1mhz internal clock). Standard bootloading procedure doesn't runs, seems there is no SPI communication (error message "avrdude: stk500_getsync(): not in sync: resp=0x66")

fuses used for bootloader

atmega8bb.name=ATmega8 on a breadboard (8 MHz internal clock)

atmega8bb.upload.protocol=stk500 atmega8bb.upload.maximum_size=7168 atmega8bb.upload.speed=9600

atmega8bb.bootloader.low_fuses=0xD4 atmega8bb.bootloader.high_fuses=0xCA atmega8bb.bootloader.path=arduino:atmega8 atmega8bb.bootloader.file=ATmegaBOOT.hex atmega8bb.bootloader.unlock_bits=0xFF atmega8bb.bootloader.lock_bits=0x0F

atmega8bb.build.mcu=atmega8 atmega8bb.build.f_cpu=8000000L atmega8bb.build.core=arduino:arduino

Anyone can help?

What ISP device are you using?

You could use my hex file uploader here:

http://www.gammon.com.au/forum/?id=11638

That requires an SD card.

The bootloader uploader sketch here should work:

http://www.gammon.com.au/forum/?id=11635

I just modified the "bootloader uploader" sketch to have the Atmega8A signature and bootloader. I'm not certain if I got it right, as I don't have that processor here to test, but I hope so.

The wiring (for connecting the programmer to the chip) should be the same as shown for the Atmega328P.

If on a breadboard this should be:

Arduino Uno         Target Atmega8 / Atmega328

D10 (SS)            Reset (pin 1)
D11 (MOSI)          Pin 17
D12 (MISO)          Pin 18
D13 (SCK)           Pin 19

Gnd                 Gnd (pins 8 and 22)
+5V                 +5V (pins 7 and 20)

Sorry not specified exact details. I'm use arduino as ISP http://arduino.cc/en/Tutorial/ArduinoToBreadboard

Nick Gammon , I doesn't have any hardware programmer.

I suppose there is problem with SCK rate, Arduino tries to program too fast. Later I'll try to to set SCK rate to 125khz. Here is some info http://www.avrfreaks.net/index.php?name=PNphpBB2&file=viewtopic&t=99652

Now I have avrdude: Yikes! Invalid device signature. Double check connections and try again, or use -F to override this check.

:~

Tried optiLoader from https://github.com/WestfW/OptiLoader result is here

OptiLoader Bootstrap programmer. 2011 by Bill Westfield (WestfW)

Target power on! ... Starting Program Mode...spi_init done...spi_transactionspi_waitspi_waitspi_waitspi_wait...Done - Failed, result = 0x0

Target power OFF!

Type 'G' or hit RESET for next chip

Checked SPI SCK rate, is set f/128

SPCR = 0x53;  // SPIE | MSTR | SPR1 | SPR0

It appeared that fuses aren't factory default, clock was set to external cristal 8mhz, after connect 8mhz cristal, optiloader worked, then I played with ArduinoISP sketch with boards file

atmega8bb.name=ATmega8 on a breadboard (8 MHz internal clock)

atmega8bb.upload.protocol=stk500
atmega8bb.upload.maximum_size=7168
atmega8bb.upload.speed=9600

atmega8bb.bootloader.low_fuses=0xD4
atmega8bb.bootloader.high_fuses=0xCA
atmega8bb.bootloader.path=arduino:atmega8
atmega8bb.bootloader.file=ATmegaBOOT.hex
atmega8bb.bootloader.unlock_bits=0x3F
atmega8bb.bootloader.lock_bits=0x2F

atmega8bb.build.mcu=atmega8
atmega8bb.build.f_cpu=8000000L
atmega8bb.build.core=arduino:arduino

(changed unlock/lock bits) and seems it worked.

kaor:
Nick Gammon , I doesn’t have any hardware programmer.

You don’t have a hardware programmer, but you tried optiLoader.

You didn’t read the thread I linked to, did you? My thread was about using the Uno as a programmer, like optiLoader does.

[quote author=Nick Gammon link=topic=127405.msg959444#msg959444 date=1350417091]

kaor: Nick Gammon , I doesn't have any hardware programmer.

You don't have a hardware programmer, but you tried optiLoader.

You didn't read the thread I linked to, did you? My thread was about using the Uno as a programmer, like optiLoader does. [/quote]

I did. But if you read my posts, you'll understand that my problem wasn't just bootloader, due to different fuses I supposed, Atmega wasn't starting up.

Now I have another problem, I can't upload a sketch, but now I'm too tired, will continue another time.

Can't upload sketch, receive sync error. Nick Gammon , btw, that sketch gives out verification errors, therefore bootloader burning fails.

What errors?

atmega8bb.upload.maximum_size=7168 atmega8bb.upload.speed=9600 : atmega8bb.bootloader.file=ATmegaBOOT.hex

If you used optiloader to put the bootloader on there, then you have "optiboot" rather than ATmegaBOOT, and the upload speed will be 57600 if you're running at 8MHz.

Nick Gammon, verification error means that bytes written doesn't mach bytes read (read was FF, therefore there is nothing written), I hasn't dig into that sketch yet, so don't sure what causes that error.

westfw, that's interesting, I'll try. Should I always put exact speed supposing that lower speed won't work?

Should I always put exact speed supposing that lower speed won't work?

Yes. None of the bootloaders suppor any form of bitrate detection. You have to talk to them at the exact bitrate that they were compiled to accept (possibly taking into account changes in clock rate. optiboot is designed to run at 115200bps at 16MHz; If you run that same code on an 8MHz cpu, it will go (exactly) 57600 (half the clock rate, half the bitrate.))

Compiling the bootloader to accept a lower bitrate MIGHT improve reliability of uploads, IF certain types of error are involved...

I'm success now, but I don't know why :D Anyway, thanks to westfw for the hint. What I did: I've tried 57600 serial rate with optiloader bootloader uploaded, and received another error

Binary sketch size: 918 bytes (of a 7,168 byte maximum) avrdude: Yikes! Invalid device signature. Double check connections and try again, or use -F to override this check.

I suppose there is problem with lock bits. Anyway, than I've tried Arduino standard bootloader

atmega8bb.bootloader.path=arduino:atmega8
atmega8bb.bootloader.file=ATmegaBOOT.hex

Uploaded via ArduinoISP sketch using Arduino IDE tool (burn bootloader). After upload, I've played with several rates for sketch uploading and got success with 9600. But receiving again the same error about invalid signature. Than I tried old IDE 0022 version and it worked :))) I suppose it uses that "-F" switch for avrdude for overriding signature or lock bits.

BTW, I tried noxtal bootloader http://todbot.com/blog/2009/05/26/minimal-arduino-with-atmega8/ And none of serial rates worked. They say serial speed 38400 should work, but it doesn't, neither any other speed from 2400 to 57600.

kaor: Nick Gammon, verification error means that bytes written doesn't mach bytes read (read was FF, therefore there is nothing written), I hasn't dig into that sketch yet, so don't sure what causes that error.

Try changing the line:

  SPI.setClockDivider (SPI_CLOCK_DIV64);

to:

  SPI.setClockDivider (SPI_CLOCK_DIV128);