M41T62 RTC Alarm
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2021-08-06 03:34 AM
Hello,
We are currently using the M41T62 RTC which is connected to a STWINKT1B board from ST along with the drivers meant to be used with M41T62(download page).
We have been successfully able to use it to set a 1 min alarm with interruptions in repetitive mode.
The same was possible with a 1-hour alarm with interruption. We followed the guidelines given for the TIMEKEEPER series application note that tells us to set RTP5, RTP4, RTP3, RTP2, and RTP1 to set the right repetitive alarms.
The problem we have is that we are unable to set it for in-between durations such as 1 min or 30 mins or 5 mins. Can you help us out with this?
/*
Simple Test code
*/
M41T62_Date_st Date = { 0, 0, 0, 0, 0 };
M41T62_Time_st Time = { 0, 0, 0, 0 };
uint32_t rtcECntr = 0;
uint32_t pre_rtcECntr = 0;
M41T62_AF_State_et af = M41T62_AF_LOW;
M41T62_Alarm_st alarm = { 0, 0, 0, 0, 10 };
int ret = BSP_ERROR_NONE;
/*
Check for I2C Device
*/
for (int i = 1; i < 256; i++) {
ret = HAL_I2C_IsDeviceReady(&hi2c4, (uint16_t) (i << 1), 3, 5);
if (ret == HAL_OK) {
msg_info("\nDevice Id = %02d", i);
}
}
/*
Read Date/Time from STM32 internal RTC
*/
/* Get the RTC current Time */
HAL_RTC_GetTime(&hrtc, &start_rtctime, RTC_FORMAT_BIN);
/* Get the RTC current Date */
HAL_RTC_GetDate(&hrtc, &start_rtcdate, RTC_FORMAT_BIN);
Time.Hours = start_rtctime.Hours;
Time.Minutes = start_rtctime.Minutes;
Time.Seconds = start_rtctime.Seconds;
Time.Seconds_10Ths = start_rtctime.SecondFraction;
Date.DayMonth = start_rtcdate.Date;
Date.DayWeek = start_rtcdate.WeekDay;
Date.Month = start_rtcdate.Month;
Date.Year = start_rtcdate.Year;
if(M41T62_Setting_Date(Date) != M41T62_OK)
msg_error("\nM41T62_Setting_Date()");
if(M41T62_Setting_Time(Time) != M41T62_OK)
msg_error("\nM41T62_Setting_Time()");
alarm.AlSeconds = 0X30;
alarm.AlMinutes = 0x01;
M41T62_Get_AF_Bit(&af);
M41T62_Set_AFE_Bit(M41T62_AFE_LOW);
if(M41T62_Disable_Alarm() != M41T62_OK)
msg_error("\nM41T62_Disable_Alarm()");
if(M41T62_Setting_DefaultBit() != M41T62_OK)
msg_error("\nM41T62_Setting_DefaultBit()");
if(M41T62_Alarm_Setting(alarm) != M41T62_OK)
msg_error("\nM41T62_Alarm_Setting()");
if(M41T62_Alarm_Repeat_Mode_Setting(M41T62_OnceperHour) != M41T62_OK)
msg_error("\nM41T62_Alarm_Repeat_Mode_Setting()");
/*
Set Alarm Enable Bit
*/
M41T62_Set_AFE_Bit(M41T62_AFE_HIGH);
HAL_Delay(100);
M41T62_Get_AF_Bit(&af);
msg_info("\n\n");
rtcECntr = 0;
/*
Loop through and check for Alarm Bit
*/
while (1) {
HAL_Delay(1000);
M41T62_Get_AF_Bit(&af);
if (af == M41T62_AF_HIGH) {
msg_info("\n========> Alarm AF Set");
ret = M41T62_Getting_Time(&Time);
if (ret == M41T62_OK) {
msg_info("\tTime:%02d:%02d:%02d:%02d\t%02ld\t%02lds\n", Time.Hours,
Time.Minutes, Time.Seconds, Time.Seconds_10Ths,
rtcECntr, (rtcECntr - pre_rtcECntr));
pre_rtcECntr = rtcECntr;
}
else
{
msg_error("\nM41T62_Getting_Time Failed!")
}
} else {
msg_info(".");
}
M41T62_ReadRegs(M41T62_AL_MONTHREG, 5, tmp);
rtcECntr++;
}
Attaching below is a reference code that we are currently running.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2021-08-09 04:30 AM
The repeat modes in the M41T62 are only able to repeat once per second/minute/hour/day/month or year (datasheet, table 7). You need to reprogram the RTC after each alarm if you need different repetition time intervals.
Regards
/Peter
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2021-08-09 04:39 AM
Hi Peter,
Thanks for your response. I am doing that in my main application. But I can't get the M41T62 alarm to work other than once per second/minute/hour/day.
Is it possible to share some sample working code where the M41T62 alarm is set to 5 mins, repetitive ? Please.
Kind Regards
Chandrashekar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2021-08-11 02:53 AM
You can set the alarm clock to any time. However, you will have to calculate and reprogram the following alarm time every time if you need something similar to the repeat modes.
With the generic C driver STSW-M41T62 it should be easy to reset the alarm clock.
Regards
/Peter
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2021-08-11 05:14 AM
Hi Peter,
I am already using generic C driver STSW-M41T62 and the above-mentioned code sample is based on generic C driver STSW-M41T62.
I also understand we need to calculate and reprogram the following alarm time every time if you need something similar to the repeat modes.
- Repeat mode - works as expected [as per datasheet]
- Alarm mode - doesn't work at all.
I really appreciate it if you could share a simple working example for an Alarm mode [where the alarm goes off every 5 mins]
kind regards
Chandrashekar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2021-08-11 07:33 AM
Typically, an STM32 does not need an external RTC because every STM32 is equipped with an RTC, just like the STM32L4R9ZI in the STEVAL-WINKIT1B. VBAT is connected to VDD, whereby it must be taken into account that WINKT1B is only an evaluation tool and not intended for productive use.
But even with internal RTC, recurring alarms would have to be calculated, which means some effort, especially at the hour/day/month and/or year limits, especially because the leap years also have to be taken into account.
It could therefore be easier to program the 1 minute repetition for recurring alarms every 5 minutes and simply to ignore 4 alarm events.
Regards
/Peter