- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
I have a very strange problem with a CY8C4248LQI-BL583 device and the RTC component.
I configured the RTC with alarm and I want to trigger a daily action with the alarm,
To test the periodic alarm feature I tried to create a minutely, an hourly or a daily alarm.
But only the daily alarm triggers correcty and it triggers only once.
I use the following code to set the alarm:
RTC_SetAlarmMask( RTC_ALARM_SEC_MASK | RTC_ALARM_MIN_MASK | RTC_ALARM_HOUR_MASK ); // Set periodic daily alarm
RTC_SetAlarmHandler( AlarmCallbackHandler ); // set Callback Handler for Alarm
RTC_DATE_TIME MyAlarm;
MyAlarm.date = RTC_SetDay( MyAlarm.date, 22 );
MyAlarm.date = RTC_SetMonth( MyAlarm.date, RTC_APRIL);
MyAlarm.date = RTC_SetYear( MyAlarm.date, 2018 );
MyAlarm.time = RTC_SetHours( MyAlarm.time, 11 );
MyAlarm.time = RTC_SetMinutes( MyAlarm.time, 55 );
MyAlarm.time = RTC_SetSecond( MyAlarm.time, 1 );
RTC_SetAlarmDateAndTime( &MyAlarm ); // Alarm is triggered on the next day at 11:55:01
// But Alarm is triggered only once, and not repeated on the day after tomorrow.
This is the Alarm-callback:
void AlarmCallbackHandler(){
RTC_ClearAlarmStatus(); // Clear Alarm Status
LED_Write( ~LED_READ() ); // toggle LED to detect the alarm has occured
}
What also does not work:
RTC_SetAlarmMask( RTC_ALARM_SEC_MASK | RTC_ALARM_MIN_MASK ); // Set periodic hourly alarm
// or:
RTC_SetAlarmMask( RTC_ALARM_SEC_MASK ); // Set periodic minutely alarm
// Same setup/configuration as before...
// But Alarm is NOT triggered in the next hour at minute 55 and second 01 or on each minute with minutely alarm.
Do I have to reenable the alarm somehow?
And if so, how do I do this?
Thanks a lot
Andreas
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Finally I found a very simple and effective solution: I just implemented the alarm functionality by myself!
Eliminating the alarm-function in the RTC-component and implementing the necessary counter is even faster and more flexible.
My implementation is based on a uint32 counter which is decremented each second. When setting the initial alarm I used the Date-to-Unixtime to easily calculate the value of the counter until the next alarm should trigger.
In the Alarm-function I can very easily set the counter for a certain repetition rate. 60*60*24 for daily alarm, or 60*60 für hourly alarm, or even anything inbetween!
Setting the counter to 32bit-max value disables the alarm for the next 136years. 🙂
Just to keep you updated!
Andreas
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
RTC_GetAlarmDateAndTime() will return all 0's if the time entry written by RTC_SetAlarmDateAndTime() is invalid. Try reading the alarm date and time after setting it to make sure the date/time is valid and set correctly.
You also need to call RTC_Start() to start the clock. Also, the checkboxes for "Implement RTC update manually" and "Enable alarm functionality" in the component's API will change behavior as well.
You also probably want to set the settings before starting the RTC clock I think.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Finally I found a very simple and effective solution: I just implemented the alarm functionality by myself!
Eliminating the alarm-function in the RTC-component and implementing the necessary counter is even faster and more flexible.
My implementation is based on a uint32 counter which is decremented each second. When setting the initial alarm I used the Date-to-Unixtime to easily calculate the value of the counter until the next alarm should trigger.
In the Alarm-function I can very easily set the counter for a certain repetition rate. 60*60*24 for daily alarm, or 60*60 für hourly alarm, or even anything inbetween!
Setting the counter to 32bit-max value disables the alarm for the next 136years. 🙂
Just to keep you updated!
Andreas