Author Topic: problem in RTC ALARM  (Read 941 times)

0 Members and 1 Guest are viewing this topic.

Offline tariqTopic starter

  • Contributor
  • Posts: 24
  • Country: ir
problem in RTC ALARM
« on: March 01, 2021, 08:35:00 am »
hi everyone

I'm usig stm32f103 and code below to set rtc alarm every one hour

RTC_Alarm_Time.Alarm = 1;

RTC_Alarm_Time.AlarmTime.Hours=RTC_Time.Hours+1;
 if (RTC_Alarm_Time.AlarmTime.Hours>23)
{
 RTC_Alarm_Time.AlarmTime.Hours=0;
 }
 RTC_Alarm_Time.AlarmTime.Hours=RTC_Time.Hours;
RTC_Alarm_Time.AlarmTime.Minutes=RTC_Time.Minutes;
RTC_Alarm_Time.AlarmTime.Seconds=RTC_Time.Seconds;
HAL_RTC_SetAlarm_IT(&hrtc, &RTC_Alarm_Time, RTC_FORMAT_BIN);

my problem is that alarm skips hour zero and after hour 23 it goes to hour 1. 

I don't know maybe because when i set alarm hour to 0 RTC date is still previous day.I'm using stm32f103 so in my library i can't define alarm Mask that ignores date in alarms.


appreciate your help.
« Last Edit: March 03, 2021, 05:18:14 pm by tariq »
 

Offline SiliconWizard

  • Super Contributor
  • ***
  • Posts: 15127
  • Country: fr
Re: problem in RTC ALARM
« Reply #1 on: March 03, 2021, 05:40:40 pm »
A quick look at your code seems to show there is basic programming problem.

If you don't have a debugger at disposal, try to execute "by hand" your code on paper (it's small so it'll be simple and fast to do.)
You'll see what your problems are.

I can see at least two. But the most obvious one is that you first increment 'TC_Alarm_Time.AlarmTime.Hours' (and wrap it around for 24 hours), but then you set it 'RTC_Time.Hours' (which I assume is the current time?), so your incremented value is just lost.
Code: [Select]
RTC_Alarm_Time.AlarmTime.Hours=RTC_Time.Hours;
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf