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
#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 ?