Pages: [1]   Go Down
Author Topic: Help supply clock signal from Arduino (to debrick AVR)  (Read 1353 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 38
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

In error, I set a fuse bit on my ATtiny85 to expect an external clock (lfuse:w:0x62:m) instead of a crystal (lfuse:w:0x6f:m).

That locked me out of running or reprogramming it, but I imagined I could reprogram it if I simply supplied the desired clock signal, using PWM from another Arduino. However, what I set up isn't doing the trick. Anybody care to help troubleshoot? (Or is the whole concept faulty?)

The setup



I'm using the Arduino UNO as ISP (that's also what I used to brick the ATtiny85).  I'm using the Arduino MEGA to supply a pulse for the clock.

The sketch on the Mega (for supplying the pulse) is as follows:

Code:
void setup()
{
  setup2560();
}

void setup2560()
{
  // OC0A is PB7, i.e. D13
  pinMode(13, OUTPUT);
  // PWM mode, non-inverted
  TCCR0A = (3<<WGM00) | (2<<COM0A0);
  // use Output Compare Register A, no prescaling
  TCCR0B = (1<<WGM02) | (1<<CS00);
  // Output Compare Register A
  OCR0A = 4;
}

void loop()
{
}

My command to avrdude is:
avrdude -p attiny85 -P com8     -c stk500v1    -b 19200 -U flash:w:main.hex

The error message
Code:
avrdude.exe: Device signature = 0x000000
avrdude.exe: Yikes!  Invalid device signature.
             Double check connections and try again, or use -F to override
             this check.

The error message is exactly what it was when the ATtiny85 had a crystal hooked up instead of the Arduino MEGA. (And same as when nothing was connected for clock.)

I didn't do any math to ensure that my MEGA's pulse frequency should equal the 16MHz which I instructed the ATtiny85 to expect (back when I bricked it). But I don't suppose that matters so much as the fact that the pulse is well over four times as fast as the programmer's Overriding Baud Rate of 19200 (which I set in the args for avrdude).
« Last Edit: June 01, 2012, 12:57:52 am by Vaselinessa » Logged

Offline Offline
God Member
*****
Karma: 3
Posts: 813
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I'm assuming the hook-up is correct, but you really should check it against the data sheet for the device.

Did you look at that clock on a scope? It should have the same duty cycle for "on" as for "off." If "4" is your compare value, the PWM should run with TOP=8.

Also, when running with a slower clock, you should use a higher delay value in the ISP. You may need to delay as much as 1 millisecond between each bit. With avrdude, this is the -i option. Start with -i 100 and see how it goes.
Logged

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 452
Posts: 18694
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I uploaded that and got no output. However this outputs 4 MHz:

Code:
void setup()
{
  setup2560();
}

void setup2560()
{
  // OC0A is PB7, i.e. D13
  pinMode(13, OUTPUT);
  // CTC, toggle output
  TCCR0A = (1<<WGM01) | (1<<COM0A0);
  // no prescaling
  TCCR0B = (1<<CS00);
  // Output Compare Register A
  OCR0A = 1;
}

void loop()
{
}
Logged

Global Moderator
Dallas
Offline Offline
Shannon Member
*****
Karma: 176
Posts: 12285
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

In error, I set a fuse bit on my ATtiny85 to expect an external clock (lfuse:w:0x62:m) instead of a crystal (lfuse:w:0x6f:m).

Which core are you using that you have to set the fuses "by hand"?

Quote
(Or is the whole concept faulty?)

The concept is not faulty.  It works well.  Supply a reasonable clock (I typically use 1 MHz for no particle reason) to the XTAL1 pin and you're good to go.

Quote
I didn't do any math to ensure that my MEGA's pulse frequency should equal the 16MHz which I instructed the ATtiny85 to expect (back when I bricked it). But I don't suppose that matters so much

It doesn't.  Any clock should work.

In addition to Nick's code, Lady Ada has published a version of ArduinoISP that outputs a "recovery clock".  If Nick's code doesn't help and you have trouble finding Lady Ada's sketch, send me a Personal Message; I have something that works.
Logged

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 452
Posts: 18694
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I have another stand-alone sketch for the Atmega328:

Code:
// For Atmega328

void setup ()
  {
  // set up 8 MHz timer on pin 9
  pinMode (9, OUTPUT);
  // set up Timer 1
  TCCR1A = _BV (COM1A0);  // toggle OC1A on Compare Match
  TCCR1B = _BV(WGM12) | _BV(CS10);   // CTC, no prescaling
  OCR1A =  0;       // output every cycle
  }
 
void loop () {}
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 38
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Wow! Thank you all for your assistance. (NIck's code worked great for de-bricking to ATtiny.)

jwatte, I have no oscilloscope. Perhaps that will be on my wish list ere long.
Logged

Pages: [1]   Go Up
Jump to: