Xmega16 RTC init

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

I thought the code below was all i needed to init the RTC, but i guess i'm missing something !!?

I'm using an RTC ISR to drive a LCD display, but the LCD doesn't do anything ( LCD driver code's good ).

Latest Winavr and PN.

void RTC_init ( volatile  RTC_t * rc )
{



	/* Turn on internal 32kHz. */
    OSC.CTRL |= OSC_RC32KEN_bm;

	do {
		/* Wait for the 32kHz oscillator to stabilize. */
	} while ( ( OSC.STATUS & OSC_RC32KRDY_bm ) == 0);

PMIC_CTRL |= PMIC_LOLVLEN_bm; // Set Int. priority level in PMIC

rc-> PER = 1; // Next 3 lines must be in this order.
 
rc-> CTRL = RTC_PRESCALER_DIV1_gc; // div by 1

rc -> INTCTRL=0x01; // Set Int. priority level in RTC
	
CCP = 0xD8;
	/* Set internal 32kHz oscillator as clock source for RTC. */
CLK_RTCCTRL = CLK_RTCSRC_RCOSC_gc | CLK_RTCEN_bm;	

}

1) Studio 4.18 build 716 (SP3)
2) WinAvr 20100110
3) PN, all on Doze XP... For Now
A) Avr Dragon ver. 1
B) Avr MKII ISP, 2009 model
C) MKII JTAGICE ver. 1

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

Got it ! I looked at *.lss and 0 was being assigned to every rtc reg where i used -> operator ( i only bothered w/ that to begin getting experience w/ it.).

Correct code follows.

void RTC_init ( void )
{

//   RTC_t * rc;

	/* Turn on internal 32kHz. */
    OSC_CTRL |= OSC_RC32KEN_bm;

	do {
		/* Wait for the 32kHz oscillator to stabilize. */
	} while ( ( OSC.STATUS & OSC_RC32KRDY_bm ) == 0);

PMIC_CTRL |= PMIC_LOLVLEN_bm; // Set Int. priority level in PMIC

RTC_PER = 1024; // Next 3 lines must be in this order.
 
RTC_CTRL = RTC_PRESCALER_DIV1_gc; // div by 1

RTC_INTCTRL=  0x01; // Set Int. priority level in RTC	

	/* Set internal 1.024 kHz oscillator as clock source for RTC. */
CLK_RTCCTRL = CLK_RTCSRC_RCOSC_gc | CLK_RTCEN_bm;

while( ( RTC_STATUS &= 0x01 ) );

}

1) Studio 4.18 build 716 (SP3)
2) WinAvr 20100110
3) PN, all on Doze XP... For Now
A) Avr Dragon ver. 1
B) Avr MKII ISP, 2009 model
C) MKII JTAGICE ver. 1