Kinetis SDK 1.3 RTC Alarm

cancel
Showing results for 
Search instead for 
Did you mean: 

Kinetis SDK 1.3 RTC Alarm

487 Views
jasonphilippi
Contributor III

Hello,

 

If I have initialized a repeat alarm, will using RTC_DRV_SetAlarm set the repeat alarm for the new time? Also will it increment the alarm when it expires?

 

Thank you,

 

Jason P

Labels (1)
0 Kudos
3 Replies

183 Views
DavidS
NXP Employee
NXP Employee

Hi Jason,

You cannot just add in that function call to enable repeat alarm operation (or at least I do not think you can).

I took the existing rtc demo from the following path in KSDK_1.3:

C:\Freescale\KSDK_1.3.0\examples\frdmk64f\driver_examples\rtc

I modified it to set up RTC for repeat alarm that will repeat once a minute (currently the repeat alarm configured for resolution of 1 minute or longer time).

The source code is attached (main.c) and all you have to do is change a #define to use default code or use repeat alarm mode:

#define REPEAT_ALARM_TEST 1//DES 1=repeat alarm test, 0=default code

Regards,

David

0 Kudos

183 Views
jasonphilippi
Contributor III

David,

The code you gave addresses how to set up either a repeat alarm or single case alarm. That I do understand.

I want to adjust the alarm in the case I adjust the time due to settings or clock drift.

If I have an alarm going off every 15 minutes, and I find out my time is off forward, I don't want to wait a longer than my repeat alarm time of 15 minutes. Setting the RTC backwards causes a previously set alarm to actually take longer.

The Repeat alarm and alarm interrupt share an isr function called RTC_DRV_AlarmIntAction, which has a flaw* itself.

Since I have a repeat alarm, it calculates the new alarm time regardless of whether the alarm is a repeat alarm or the new alarm I set. I don't think there are two registers that hold alarm values, then RTC_DRV_SetAlarm should override the old alarm.

Regards,

Jason P

*RTC_DRV_AlarmIntAction had a problem with rollovers of time. Once the time passed the max of each category, it would check if the time was valid in RTC_DRV_SetAlarm. In my case if the time went passed 15 minutes, it would never alarm again. I added two lines to convert back and forth to fix it.

void RTC_DRV_AlarmIntAction(uint32_t instance)

{

    RTC_Type *rtcBase = g_rtcBase[instance];

    uint32_t seconds;

    if (s_rtcRepeatAlarmState != NULL)

    {

        s_rtcRepeatAlarmState->alarmTime.year += s_rtcRepeatAlarmState->alarmRepTime.year;

        s_rtcRepeatAlarmState->alarmTime.month += s_rtcRepeatAlarmState->alarmRepTime.month;

        s_rtcRepeatAlarmState->alarmTime.day += s_rtcRepeatAlarmState->alarmRepTime.day;

        s_rtcRepeatAlarmState->alarmTime.hour += s_rtcRepeatAlarmState->alarmRepTime.hour;

        s_rtcRepeatAlarmState->alarmTime.minute += s_rtcRepeatAlarmState->alarmRepTime.minute;

      

        RTC_HAL_ConvertDatetimeToSecs(&s_rtcRepeatAlarmState->alarmTime,&seconds); /*Edit - JRP */

        RTC_HAL_ConvertSecsToDatetime(&seconds, &s_rtcRepeatAlarmState->alarmTime); /*Edit - JRP */

      

        RTC_DRV_SetAlarm(instance, &s_rtcRepeatAlarmState->alarmTime, true);

    }

    else

    {

        /* Writing to the alarm register clears the TAF flag in the Status register */

        RTC_HAL_SetAlarmReg(rtcBase, 0x0);

        RTC_HAL_SetAlarmIntCmd(rtcBase, false);

    }

}

0 Kudos

183 Views
DavidS
NXP Employee
NXP Employee

Hi Jason,

Thanks for your workaround/fix.

I'll pass to the KSDK team.

Regards,

David

0 Kudos