ATXMEGAA1U-XPRO RTC interrupt

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

I need to use the 32 kHz external oscillator on the xmegaa1uxplained pro eval board. I need a 5 ms RTC clock. The RTC is completing the initialization but the RTC interrupt is not triggering. What is missing/wrong from the setup below? Thanks

 

void vRtcInitialize (void)
{
    /* Turn on external oscillator (32kHz on board). */
    OSC.XOSCCTRL |= OSC_XOSCSEL_32KHz_gc;
    OSC.CTRL |= OSC_XOSCEN_bm;

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

    /* Set clock source for RTC to 32kHz on board oscillator. */
    CLK.RTCCTRL = CLK_RTCSRC_TOSC32_gc | CLK_RTCEN_bm;

//set RTC period to approx 5 ms
    RTC.PER = 163;    //32768/163 = 5ms
    RTC.INTCTRL = RTC_OVFINTLVL_LO_gc;
    while(RTC.STATUS & RTC_SYNCBUSY_bm);
    
}

ISR(RTC_OVF_vect){
    RTC.INTFLAGS = RTC_OVFIF_bm;
    _systemTicks += 1UL;
}

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

I take it there is an sei() in all this somewhere ?

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

The sei() is called before initializing the RTC, even before system_init. I added 

    /* Enable interrupts. */
    PMIC.CTRL |= PMIC_LOLVLEN_bm;

 

to the bottom of RTC_initialize. It doesn't make a difference.

 

Thanks,

Priya

 

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

fwe wrote:
 sei() is called before initializing the RTC,

Not generally a good idea to enable an interrupt before you've correctly configured stuff.

 

Please post a minimum but complete example which illustrates the problem

 

See Tip #1 in my signature, below for how to properly post source code:

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0
#define F_CPU (4000000UL)

#include <asf.h>
#include "conf_usb.h"
#include "ui.h"
#include "uart.h"
#include "tmrmodule.h"
#include "timeout.h"

extern volatile ticksize_t _systemTicks;
static volatile bool main_b_cdc_enable = false;
void vRtcInitialize(void);
void vIOWiegTimeout(void);

uint8_t bWiegData = FALSE;

/*! \brief Main function. Execution starts here.
 */
int main(void)
{
	iram_size_t len = 6;
	char buf[6] = {'G', 'R', 'E', 'A', 'T', '\n'};
	uint16_t    chktick = 0;
	


	// Initialize the sleep manager
//	sleepmgr_init();

#if !SAM0
	sysclk_init();
	board_init();
#else
	system_init();
#endif
	vRtcInitialize();
		irq_initialize_vectors();
		cpu_irq_enable();
	
	vTmrInit();
	vTmrCfgFnct (WIEG_TIMER, (void *)vIOWiegTimeout, (void *)0);		// config WIEG timer
	vTmrSetT(WIEG_TIMER, 5);

//	ui_init();
//	ui_powerdown();

	// Start USB stack to authorize VBus monitoring
//	udc_start();

	// The main loop manages only the power mode
	// because the USB management is done by interrupt
	while (true) {
		chktick = to_GetTicks();
		while (chktick > 0)
		{
			vTmrSignalTmr();	// update system timer
			chktick--;
		}
//		sleepmgr_enter_sleep();
//		udi_cdc_write_buf(buf,len);		
	}
}

void vRtcInitialize (void)
{
	/* Turn on external oscillator (32kHz on board). */
	OSC.XOSCCTRL |= OSC_XOSCSEL_32KHz_gc;
	OSC.CTRL |= OSC_XOSCEN_bm;

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


	/* Set clock source for RTC to 32kHz on board oscillator. */
	CLK.RTCCTRL = CLK_RTCSRC_TOSC32_gc | CLK_RTCEN_bm;

//set RTC period to approx 5 ms
	RTC.PER = 163;    //32768/163 = 5ms
	RTC.INTCTRL = RTC_OVFINTLVL_LO_gc;
	while(RTC.STATUS & RTC_SYNCBUSY_bm);
	
}

ISR(RTC_OVF_vect){
	RTC.INTFLAGS = RTC_OVFIF_bm;
	_systemTicks += 1UL;
}

 

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

I got the RTC_EXAMPLE1 setup to use the external 32kHz crystal and with RTC PER 5 ms. I am now able to get the RTC interrupt to trigger. I had to use ASF to add the RTC driver to the project. Now I need to use it the way the application needs.