# ATtiny External Clock not working

So, I've been wanting to break away from the arduino abstraction for a while now. I made a board that has an ATtiny10 on it with a crystal and an output. I cannot for the life of me understand what I am doing wrong.

Here's the problem: When I select the clock source, the AVR stops working.

I had a custom PCB (small one) made to mount everything on. Thinking I didn't do something right (even though schematic looked right)

I changed design and made another one (for the second one, I had traces with clock surrounded by a ground plane (Did not work still) [Also, the first design was using everything but the AVR sourced from ebay. Thinking maybe it was a quality issue the second board is sourced entirely from Mouser]

Lastly, to make sure I wasn't an absolute idiot, I bought a breakout board and just breadboarded the circuit. This still performed just like all the others

It works just fine with the internal oscillator, but as soon as I program to change clock source it stops.

Note that I added R2 to keep the MOSFET pulled down but I do not populate it for programming it, as TPI (Tiny Programming Interface) uses pullups on that line and I cannot populate that if I am going to program the chip

Page 21 of the datasheet regarding changing clock

Page 22 of the datasheet regarding the prescaler (Clock prescaler not timer prescaler)

I am using a MkII programmer from Atmel and these are the fuse bits:

Output External Clock

0xFB

This was set through Atmel studio and I have used a couple different ATtiny's and the chips kept these settings once set, so I am pretty sure the fuses are writing correctly

Now the code: (This is the whole program, the timer portion works (obviously not though once the clock switches))

#define F_CPU   8000000

#include <avr/io.h>
#include <avr/interrupt.h>

void initClock()
{
// Setting CLKPSR does not affect the problem (It doesn't work regardless of what this is set to)
// I have tried this before and after setting CLKMSR

CCP = 0xD8;
CLKPSR = 0;

CCP = 0xD8;
CLKMSR = 0b10;

}

void initPorts()
{

DDRB |= (1 << PORTB0); // PB0 = OCR0A
}

void initTimer()
{
// I posted this code just in case, this works as expected (but only on the internal oscillator)

// We want Compare Output Mode, Clear OC0A on Compare Match
TCCR0A =    (1 << COM0A0);

// Overflow setting
TIMSK0 |= (1 << OCIE0A);

// We will not use a prescaler
// This also starts the timer
TCCR0B =    (1 << CS00) | (1 << WGM02);

// This is the value at which the timer will restart
OCR0A = 8299;

// Set external interrupts
sei();

}

int main(void)
{
initClock();
initPorts();
initTimer();

while(1)
{

}
}


Surely there has to be something I am missing. I've tried to read and reread the especially the clock sections of the datasheet in order to figure it out myself. I am stumped though. Maybe someone could help me understand my mistake.

Attiny10 Datasheet

• try to write a 0 to CLKM0, if it's a 1 you end up with the 'reserved' combination and who knows what can happen. Aug 1, 2014 at 7:55
• @VladimirCravero I set that bit to 0 and it does not start the external clock
– Dan
Aug 1, 2014 at 7:57
• That bit is zero anyway on reset, but I can't see where in your code you set it to zero. Aug 1, 2014 at 7:59
• @VladimirCravero sorry, I meant I did change that after you asked. I will edit to reflect the change. Sorry for the misunderstanding
– Dan
Aug 1, 2014 at 8:01