RTC - first steps

Hello.

 

I'm trying to implement RTC feature but I don't find any example for SSP1.2.0. Does anybody have one/know where to find it? I'm using a S7G2-DK based custom board, but I could use a PE-HMI1 board project as well.

 

Reading the user manual, I have some questions:

1. Do I have to pur the RTC driver in the HAL layer or is it possible to put it in a thread?

2. Right now, I'm using PLL as clock source in my application project. Is it necessary to use LOCO/SUBCLK clock as source to be able to use RTC? Or is it enough configuring the Clock source in the properties of the driver? 

    

3. Do I have to implement anything regarding the ICU tab? Is this tab really used in SSP1.2.0? Because I don't see anything to configure on it (comparing it to SSP1.1.3 version)

Regards,

isaenz.

  • There is some code for the rtc in the Developer Examples. You can ad them to your project via Synergy Configuration, Components tab, Projects. The examples are in the file r_rtc_commands.c
  • Hi isaenz,

    1. No, you can put in the thread or HAL/Common.
    2. Yes, RTC allows to set only LOCO or Sub-clock as the clock source.
    3. No, however you should enable necessary interrupts in the module using its configuration settings.

    Regards,
    adboc
  • In reply to josh222:

    Thanks  but I only see the blinky projects there... 

    Have these Developer Examples been released for SSP1.1.2? I've found them for SSP1.1.0 inside a different version of e2studio I have installed. I'm going to try following this file.

    Regards,

    isaenz.

  • In reply to isaenz:

    Hi isaenz,

    Adding a RTC Driver to your application using the configuration is relatively simple. Just add it to your thread or HAL/Common, configure it (including setting necessary interrupt priorities to an enabled level), implement a callback and initialize this module in your code.

     

    bsp_leds_t leds;

    void initRTC( void );

    void initRTC( void )
    {
        ssp_err_t err;

        R_BSP_LedsGet(&leds);

        err = g_rtc.p_api->open(g_rtc.p_ctrl, g_rtc.p_cfg);

        if (SSP_SUCCESS != err)
        {
            __BKPT(0);
        }

        err = g_rtc.p_api->periodicIrqRateSet(g_rtc.p_ctrl, RTC_PERIODIC_IRQ_SELECT_1_SECOND);

        if (SSP_SUCCESS != err)
        {
            __BKPT(0);
        }

        err = g_rtc.p_api->calendarCounterStart(g_rtc.p_ctrl);

        if (SSP_SUCCESS != err)
        {
            __BKPT(0);
        }

        err = g_rtc.p_api->irqEnable(g_rtc.p_ctrl, RTC_EVENT_PERIODIC_IRQ);

        if (SSP_SUCCESS != err)
        {
            __BKPT(0);
        }
    }


    void rtc_callback(rtc_callback_args_t *p_args)
    {
        static char i = 0;

        if(p_args->event == RTC_EVENT_PERIODIC_IRQ)
        {
            /*Blink LED*/
            g_ioport.p_api->pinWrite(leds.p_leds[1], i);
            i = i ^ 1;
        }
    }
     
     
    Remember to call initRTC function in your entry function.
     
    Regards,
    adboc
  • In reply to adboc:

    Hello isaenz,

    Regarding your question from earlier: "Right now, I'm using PLL as clock source in my application project. Is it necessary to use LOCO/SUBCLK clock as source to be able to use RTC? Or is it enough configuring the Clock source in the properties of the driver?"

    PLL is the clock source for peripheral clocks specified in the clock tree. RTC is in a separate hardware block where it is powered using VBATT (if available) and clocked using LOCO or Sub-oscillator - both of which are independent from your main clock source. Leaving default clock configuration is recommended. Specifying clock source in the RTC is optional, however selecting sub-oscillator when VBATT is fitted (not found on the SK-S7), will maintain RTC operation when the board is powered down. This is not possible with LOCO.

    Regards
  • In reply to adboc:

    Thanks adboc (7bf5fa65-815a-49c6-b33d-f44b7c4fa880) ,

    I'm trying to implement this but I get a SSP_ERR_TIMEOUT when I try to open the g_rtc.

    My project consists of different threads and I've created a new thread with de RTC driver. Here's the configuration:

    This is the code I'm using, but it gets stuck in the open command, so the RTC_callback is never reached:

    void RTC_entry(void)
    {
        ssp_err_t err;

        err = g_rtc.p_api->open(g_rtc.p_ctrl, g_rtc.p_cfg);
        if (SSP_SUCCESS != err)
        {
            while(1);
        }

        err = g_rtc.p_api->periodicIrqRateSet(g_rtc.p_ctrl, RTC_PERIODIC_IRQ_SELECT_2_SECONDS);
        if (SSP_SUCCESS != err)
        {
            while(1);
        }


        err = g_rtc.p_api->calendarCounterStart(g_rtc.p_ctrl);
        if (SSP_SUCCESS != err)
        {
            while(1);
        }

        err = g_rtc.p_api->irqEnable(g_rtc.p_ctrl,RTC_EVENT_PERIODIC_IRQ);
        if (SSP_SUCCESS != err)
        {
            while(1);
        }

         while (1)
        {
            tx_thread_sleep (1);
        }
    }

    void RTC_callback(rtc_callback_args_t * p_args)
    {
        ssp_err_t err;
        int status;
        rtc_time_t time_read;
        int queue_message[4];

        /* send time */
        err = g_rtc.p_api->calendarTimeGet(g_rtc.p_ctrl, &time_read);
        if (SSP_SUCCESS != err)
        {
            while(1);
        }

        queue_message[0] = time_read.tm_hour;
        queue_message[1] = time_read.tm_min;
        queue_message[2] = time_read.tm_sec;
        queue_message[3] = time_read.tm_wday;
        status = tx_queue_send(&g_RTC_queue, queue_message, TX_16_ULONG);

    }

    Any suggestion?

    Regards,

    isaenz.

  • In reply to isaenz:

    Hi again
    I managed to get the RTC working, but only if I set LOCO as clock source, with Sub-Clock the driver stucks in the open function.
    Any idea why this is happening?
    Regards,
    isaenz.
  • In reply to isaenz:

    Does adding a 2-3 seconds sleep before the open call help? Alternatively you may use sub-clock and before opening the RTC timer, include the following lines:

    g_cgc.p_api->clockStart(CGC_CLOCK_SUBCLOCK, NULL);
    R_BSP_SoftwareDelay(2, BSP_DELAY_UNITS_SECONDS);

    --EDIT--

    If you need to user Sub-Clock, please try the above lines before opening the RTC driver. Note that using Sub-Clock over LOCO can slightly improve accuracy and is useful in batterry-powered applications. In most cases LOCO is sufficient.


    Regards,
    adboc

  • In reply to adboc:

    thanks adboc (7bf5fa65-815a-49c6-b33d-f44b7c4fa880) ,

    Same thing keeps happening, but I'm going to analyze if LOCO is sufficient in my application and, if that's the case, I'll stick to that (although I'm affraid I'll be needing Sub-Clock, but at least I'm not stuck as I was before).

    Regards,

    isaenz.