Is it possible to use the USBtinyISP as a clock source?
Moderators: adafruit_support_bill, adafruit
Please be positive and constructive with your questions and comments.
-
- Posts: 1
- Joined: Mon Oct 29, 2012 8:39 pm
Is it possible to use the USBtinyISP as a clock source?
So I goofed up and set the lfuse bit of an Attiny84 to 0xC0 which apparently means that I set "the fuses for an external clock with no divider". I read that somehow I might be able to use the programmer as the external clock source? If that's not the case, what are my other options to restore functionality to my chip? Thanks
- adafruit_support_rick
- Posts: 35092
- Joined: Tue Mar 15, 2011 11:42 am
Re: Is it possible to use the USBtinyISP as a clock source?
Hmmm. Don't know where you read that. I don't know of a way to use the programmer as a clock source.
We stock resonators that you can use as a clock:
https://www.adafruit.com/products/1872
We stock resonators that you can use as a clock:
https://www.adafruit.com/products/1872
- nsayer
- Posts: 59
- Joined: Thu Aug 08, 2013 10:45 am
Re: Is it possible to use the USBtinyISP as a clock source?
With the fuses set that way, a resonator or crystal will not work. It's configured for a direct square wave on CLKI.
You can't use a USBTiny as a clock source, but if you happen to have an Arduino UNO handy, it's pretty easy to configure it as a square wave source to recover from bad fusing. Just write a sketch like this:
setup() { pinMode(3, OUTPUT); }
loop() {
while(1) {
digitalWrite(3, HIGH);
digitalWrite(3, LOW);
}
}
That's not going to be perfectly square, but it will be good enough. With a 16 MHz Arduino, you'll probably wind up with a clock around 1 MHz or so.
And then connect D3 to CLKI (pin 2) on your Tiny84 and attempt to re-fuse the chip. If it doesn't work immediately, try using a -B argument to avrdude to slow down the SPI clock.
You can't use a USBTiny as a clock source, but if you happen to have an Arduino UNO handy, it's pretty easy to configure it as a square wave source to recover from bad fusing. Just write a sketch like this:
setup() { pinMode(3, OUTPUT); }
loop() {
while(1) {
digitalWrite(3, HIGH);
digitalWrite(3, LOW);
}
}
That's not going to be perfectly square, but it will be good enough. With a 16 MHz Arduino, you'll probably wind up with a clock around 1 MHz or so.
And then connect D3 to CLKI (pin 2) on your Tiny84 and attempt to re-fuse the chip. If it doesn't work immediately, try using a -B argument to avrdude to slow down the SPI clock.
- nsayer
- Posts: 59
- Joined: Thu Aug 08, 2013 10:45 am
Re: Is it possible to use the USBtinyISP as a clock source?
So, since I posted that, I actually *have* figured out a way to make a USBTiny (or a clone) generate a "recovery clock" - a 500 kHz square wave that you can inject onto one or the other XTAL pin on a controller that you've accidentally fused for an external crystal.
To make it work, you have to upload new firmware. The new firmware sets up OC0A (PB2) as an output from one of the timers.
Here's the patch against the v1.7 source code:
Having done this, PB2 will have a 500 kHz square wave on it whenever programming is in progress. You need to use -B 250 with avrdude to give the target enough time to stabilize after the clock appears (when RESET is brought low), but I've used this as a test to recover an intentionally pooched ATTiny85.
To make it work, you have to upload new firmware. The new firmware sets up OC0A (PB2) as an output from one of the timers.
Here's the patch against the v1.7 source code:
Code: Select all
--- main.c.orig 2015-02-18 00:09:51.871774909 -0800
+++ main.c 2015-02-24 22:55:16.889267234 -0800
@@ -44,12 +44,14 @@
#define PIN PINB
#define LED PB0 // output
+#define RCLK PB2 // output
#define RESET PB4 // output
#define MOSI PB5 // output
#define MISO PB6 // input
#define SCK PB7 // output
#define LED_MASK _BV(LED)
+#define RCLK_MASK _BV(RCLK)
#define RESET_MASK _BV(RESET)
#define MOSI_MASK _BV(MOSI)
#define MISO_MASK _BV(MISO)
@@ -193,7 +195,7 @@
mask |= RESET_MASK;
}
CLR(BUFFEN);
- DDR = LED_MASK | RESET_MASK | SCK_MASK | MOSI_MASK;
+ DDR = LED_MASK | RESET_MASK | SCK_MASK | MOSI_MASK | RCLK_MASK;
PORT = mask;
return 0;
}
@@ -295,6 +297,11 @@
// ----------------------------------------------------------------------
extern int main ( void )
{
+ // Initialize timer 0 for 500 kHz clock on PB2 (OC0A)
+ TCCR0A = _BV(COM0A0) | _BV(WGM01); // CTC mode, toggle OC0A on match
+ TCCR0B = _BV(CS00); // No prescaling
+ OCR0A = 11; // divide system clock by 24 -> 500 kHz
+
SET(BUFFEN);
OUTPUT(BUFFEN);
usb_init();
- adafruit_support_rick
- Posts: 35092
- Joined: Tue Mar 15, 2011 11:42 am
Re: Is it possible to use the USBtinyISP as a clock source?
Interesting. Thanks for posting!
Please be positive and constructive with your questions and comments.