RTC Configuration

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

I am using a ATtiny817 xplained Mini, I want to toggle LED using overflow interrupt for every 10 sec from RTC, but i am not able generate the interrupt. Is the configurations correct?

I have configured the Main clock source 32kHz (Low Power Oscillator), using 1KHz from it to clock the RTC with no prescaler.

#define RTC_SAMPLE_PERIOD (1024 * 10)

void RTC_init(void)
{
	/* Configuring the Clock Source */
	_PROTECTED_WRITE(CLKCTRL.OSC32KCTRLA, CLKCTRL_RUNSTDBY_bm);
	_PROTECTED_WRITE(CLKCTRL.MCLKCTRLB, !CLKCTRL_PEN_bm);
	_PROTECTED_WRITE(CLKCTRL.MCLKCTRLA, !CLKCTRL_CLKOUT_bm | CLKCTRL_CLKSEL_OSCULP32K_gc);
	while (!(CLKCTRL.MCLKSTATUS & CLKCTRL_OSC32KS_bm));

	/*	Initialize RTC */
	while (RTC.STATUS > 0)
	; //Wait for All registers to be Synchronized

	/* Set Period */
	RTC.PER = RTC_SAMPLE_PERIOD;

	/* Configuring RTC CLOCK */
	RTC.CLKSEL = RTC_CLKSEL_INT1K_gc; //Selecting 1kHz from 32KHz Low Power Oscillator (OSCULP32K)

	/* Run in debug: enabled */
	RTC.DBGCTRL |= RTC_DBGRUN_bm;

	RTC.CTRLA = RTC_RTCEN_bm /* Enable: enabled */
	| RTC_RUNSTDBY_bm; /* Run In Standby: enabled */

	/* Enable Overflow Interrupt */
	RTC.INTCTRL |= RTC_OVF_bm;
}

ISR(RTC_CNT_vect)
{
	LEDupdateFlg = 1;
	RTC.INTFLAGS |= RTC_OVF_bm;
}

 

Thanks,

Jaivvignesh | Associate Firmware Developer

Last Edited: Thu. Oct 10, 2019 - 11:58 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0
	LEDupdateFlg = 1;

Is LEDupdateFlg declared as "volatile"?

 

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

Incorrect forum to post.

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

Sorry Sir.

Thanks,

Jaivvignesh | Associate Firmware Developer

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

Yes  it is volatile

Thanks,

Jaivvignesh | Associate Firmware Developer