ASF RTC driver issue

1 post / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hello,

 

I have been trying for hours to use the RTC functionality for my project based on a Xplained C3 board (Xmega 384 C3 Microcontroler).

My target is to use RTC to wake up the cpu from sleep mode every 30 seconds and then execute a task and endessly return to sleep mode.

As a beginner I have been watching many videos from Atmel channel (youtube) to see how to design a project based on ASF.

First I took the original software of the board (light and temperature sensor and many usb functionnalities) and i commented in all the main function.

Then I copied the code lines that handle the RTC functions based on he getting started RTC driver documentation.

I also set the RTC source clock in conf_clock.h :

#define CONFIG_RTC_SOURCE			SYSCLK_RTCSRC_TOSC

I also set the RTC prescaler at 1024 to get a count every second in conf_rtc.h :

#define CONFIG_RTC_PRESCALER			RTC_PRESCALER_DIV1024_gc 

 

 

Here the code I used in the main.c :

 

static void alarm(long time)
{
    //sec++;
    rtc_set_alarm(time);                // va faire RTC.COMP = time et autoriser les interruption  incomprehensible
    //message("time :",time,1);
    //message("sec",sec,1);
    LED_Toggle(LED0);
}


int main(void)
{
    
    
    pmic_init(); //Programmable Multilevel Interrupt Controller, usage non compris

    /* Initialize ASF services */
    sleepmgr_init();
    sysclk_init();
    board_init();

    rtc_init();
    rtc_set_callback(alarm);      // set alarm() as the callback function ?

    irq_initialize_vectors();         // macro ,
    cpu_irq_enable();                 // macro Enable interrupts globally.

    rtc_set_alarm_relative(0);    // what for ?
    
    /*
    sd_mmc_init();
    stdio_usb_init(); // Initialize STDIO and start USB 
    udc_stop(); // Stop USB by default 
    main_introduction();
    // Initialize tasks 
    
    app_touch_init();
    app_cpu_load_init();
    app_sampling_init();
    
    gfx_mono_init();
    gfx_mono_draw_string("My name is\r\nDANiel!\r\nWorld...",
    0, 0, &sysfont);
    
    */
    
 
    while (true) {
        
        // Enter in sleep mode 
    /*    app_cpu_load_enter_sleep();*/
        
        sleepmgr_enter_sleep();
        

    /*    //Execute tasks 
        app_usb_task();
        app_microsd_task();
        app_sampling_task();
        app_touch_task();
        app_cpu_load_task();
    */
    }

 

As it is supposed to do, the led toggles every second but i was not able to change this period for my needs.

 

Here are my questions :

 

  1. what the line :  rtc_set_alarm_relative(0) is for ?
  2. what is the role of the time parameter in alarm(time) function  ?
  3. how could i have a RTC period of 30 seconds ?
  4. Is alarm() function is made to execute a task when rtc has fired an interrupt ?

 

I really will be happy if someone could help me for this issue.

 

Thanks

French AVR user