Electronic – ATtiny External Clock not working

avrcrystal

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.

Schematic

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
Clock Settings

Page 22 of the datasheet regarding the prescaler (Clock prescaler not timer prescaler)
Clock 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.

Thank you! Please let me know if there is any more info I can add to make it easier to understand

Attiny10 Datasheet

Best Answer

Using the two leg crystal is not possible with the specific device. There is only the option to use an external clock source, so you can use an external oscillator like the following one and apply the clock pulses to the CLKI pin (pin 1).

enter image description here

Unlike the two leg crystal that needs additional circuitry inside the mcu and two capacitors, this four pin crystal oscillator is a complete oscillator that only needs power to generate the clock.