(SOLVED) ATtiny85 external crystal problem

Go To Last Post
4 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi,

I'm in the starting phase of an ATtiny85 project and have connected an external 2.4576Mhz crystal. My first milestone is to get an ISR to run every 30 seconds.

 

I set up the TIMER1 and Interrupts but noticed my ISR was not triggering so I dumbed down my code ALOT, so I am currently trying with a really simple software delay to see if the crystal/clock is as anywhere near the expected regions. This is the code I'm currently flashing:

 

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

int main(void) {
    DDRB |= (1 << DDB2);
    while(1) {
        _delay_ms(3000);
        PORTB ^= (1 << PORTB2);
    }

    return 0;
}

I can see that PORTB2 is toggling at a rate of ~7 seconds instead of 3, so I'm assuming the device runs at a different clock speed than my expected 2.4Mhz crystal.

 

So of course I suspected the fuse settings, but I checked them several times and can't see what is wrong.

F_CPU, that is used by _delay_ms, is set to 2457600UL and my fuses are:

 

LFUSE = 0xFB
HFUSE = 0xDF
EFUSE = 0xFF

As per this online generator:

 

I tried with two different crystals of the same value/manufacturer and have 22pF capacitors in place for the crystal.

 

Appreciate any advice of what I'm doing wrong, thanks.

 

This topic has a solution.
Last Edited: Sun. Dec 3, 2017 - 03:36 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

roqvist wrote:

I can see that PORTB2 is toggling at a rate of ~7 seconds instead of 3, so I'm assuming the device runs at a different clock speed than my expected 2.4Mhz crystal.

 

Which would imply that you are actually running at 1MHz.

 

roqvist wrote:

I tried with two different crystals of the same value/manufacturer and have 22pF capacitors in place for the crystal.

 

What happens if you have no crystal connected? Does it still toggle? If yes, then you haven't set the fuses correctly.

'This forum helps those who help themselves.'

 

pragmatic  adjective dealing with things sensibly and realistically in a way that is based on practical rather than theoretical consideration.

This reply has been marked as the solution. 
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Read back the fuses and make sure they are set for Ext Crystal

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thanks for your feedback. Embarrassingly enough the make command I ran actually never set the fuses, it just flashed in the code. Problem solved by actually setting the fuses... blush