Author Topic: 32.768KHz Crystal Not working  (Read 674 times)

0 Members and 1 Guest are viewing this topic.

Offline vishalTopic starter

  • Regular Contributor
  • *
  • Posts: 102
  • Country: in
32.768KHz Crystal Not working
« on: January 20, 2018, 04:56:52 am »
Hi
I am trying to enable crystal (32.768KHz) connected in TOC1 and TOC2 pins of avr-atmega256rfr2 MCU. The Code that I used to initiate the timer2 in asynchronous mode is as follows
Code: [Select]
#include <avr/io.h>
#include <avr/interrupt.h>
#include <util/delay.h>
//Prepare LED pin
void PortInit(void)
{
//Initlally LED OFF

PIND=(1<<PD6);
//PD0 as output
DDRD|=(1<<PD6);
}
//Timer2 init acording datasheet
void RTCInit(void)
{

TIMSK2=0;
ASSR=(1<<AS2);
TCNT2=0;
TCCR2B|=(1<<CS22)|(1<<CS00);
while(ASSR&((1<<TCN2UB)|(1<<TCR2BUB)));
TIFR2=(1<<TOV2);
TIMSK2=(1<<TOIE2);

}
//Overflow ISR
ISR(TIMER2_OVF_vect)
{
//Toggle pin PD0 every second
PORTD&=~(1<<PD6);
//asm volatile("nop"::);
_delay_ms(100);
}
int main (void)
{
SMCR|=(1<<SM1)|(1<<SM0);
//Initialize port
PortInit();
//Initialise the timer2
RTCInit();
//Enable global interrupts
sei();
while(1)
{
SMCR|=(1<<SE);
//asm volatile("sleep"::);
SMCR&=~(1<<SE);
//Do nothing

}
}

But the crystal is not working .Controller is working with internal RC oscillator (8Mhz).what are  the  reasons for it ?
« Last Edit: January 20, 2018, 05:11:19 am by vishal »
 

Offline phil from seattle

  • Super Contributor
  • ***
  • Posts: 1029
  • Country: us
Re: 32.768KHz Crystal Not working
« Reply #1 on: January 20, 2018, 06:45:37 am »
Haven't looked at the data sheet but the first thing that springs to mind is have you set the fuses correctly?
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf