0
\$\begingroup\$

I wrote this code:

#ifndef F_CPU
#define F_CPU 1105920UL
#endif

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

int main(void){
    DDRC=0b00100000;
    while(1){
        PORTC=0b00100000;
        _delay_ms(5000);
        PORTC=0b00000000;
        _delay_ms(1000);
    }
}

I programed it in atmega8:

sudo avrdude -c usbasp -p m8 -U flash:w:my.hex

micro programed ,OK, not problem:

i wanted use external crystal; then i connected crystal 11.0592 to pin 10 and 9, and rewrite fuse bit:

sudo avrdude -c usbasp -p m8 -U lfuse:w:0xE0:m

fuse bit rewrite and OK.not problem


now i realized this value 1105920UL is mistake, i edit code and change 1105920UL to 11059200UL ,

but when i programed micro, avrdude get me error:

$sudo avrdude  -c usbasp -p m8 -U flash:w:my.hex 

avrdude: warning: cannot set sck period. please check for usbasp firmware update.
avrdude: error: program enable: target doesn't answer. 1 
avrdude: initialization failed, rc=-1
         Double check connections and try again, or use -F to override
         this check.


avrdude done.  Thank you.

My micro is lock? or i must rewire sck? how to i resolve this problem?!?

Thank you

\$\endgroup\$
  • \$\begingroup\$ Abstracting the crystal problem - the avrdude message about the SCK means that you have old usbasm firmware. Update it and you will be able to change the sck frequency \$\endgroup\$ – P__J__ May 27 '18 at 0:18
1
\$\begingroup\$

Your problem is lfuse:0xE0 means "external clock". You have to use an integrated 8 to 16MHz crystal oscillator and connect it to XTAL1. Your device should be reprogrammable again, at least.

To use a bare crystal, you need an lfuse setting of 0xEE. But you cannot change this now, you had to connect the external oscillator you had selected before first.

\$\endgroup\$
  • \$\begingroup\$ yes, i use external crystal 11.0592 and connect it to pin 9(XTAL1) and 10(XTAL2) ,,but i can't re program my micro! \$\endgroup\$ – بارپابابا May 24 '18 at 22:43
  • \$\begingroup\$ External clock != External crystal. Please read and understand pages 27, 32, and 217 of the ATmega8 datasheet. google.com/… \$\endgroup\$ – Janka May 24 '18 at 22:45
  • \$\begingroup\$ you could use an Arduino to generate the clock signal \$\endgroup\$ – jsotola May 24 '18 at 23:59
  • \$\begingroup\$ @jsotola how to do it? \$\endgroup\$ – بارپابابا May 25 '18 at 1:38
1
\$\begingroup\$

I programed another micro (atmega16) and use it from external clock,

$regfile = "m16def.dat"
$crystal = 8000000
Config Portd = Output

Do

Toggle Portd.1
Loop

End

Or in codevision (with internal rc 8Mhz) :

while(1){
    PORTD.0 = ! PORTD.0
}

and connect D0 pin (atmega16) to xtal1 of locked micro (atmega8),

and now we can program locked micro and change fuse bit or set to default value.


U1 is atmega16 for use external clock

U2 is atmega8, locked micro, and we want change it fuse bit

imge


thank from @Janka

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.