stm32duino / STM32RTC

Arduino RTC library for STM32.
135 stars 49 forks source link

There is a bug about alarm interrupt in V1.3 #69

Closed KiraVerSace closed 2 years ago

KiraVerSace commented 2 years ago

The same environment one use the STM32RTC V1.2 one use V1.3, but the alarm interrupt is not worked in the V1.3 ,but I do not know why, I use the Stm32l476rct6

void rtcAlramInterruptInit(voidFuncPtr funPtr)
{
    uint8_t minutes = rtc.getMinutes();

    minutes = 1 + minutes;  // minutes = (5 - (minutes % 5)) + minutes;
    if(minutes == 60)
    {
        minutes = 0;
    }
    rtc.attachInterrupt(funPtr);
    rtc.setAlarmMinutes(minutes);
    rtc.setAlarmSeconds(0);
    rtc.enableAlarm(rtc.MATCH_MMSS);

    logInfo("RTC Alarm first Interrupt Minutes at [%02d]", minutes);
} 
ABOSTM commented 2 years ago

Hi @KiraVerSace your problem may be similar to https://github.com/stm32duino/STM32LowPower/issues/71https://github.com/stm32duino/STM32LowPower/issues/71 for witch I proposed a fix: https://github.com/stm32duino/STM32RTC/pull/68 You may have a try

KiraVerSace commented 2 years ago

Hi @KiraVerSace your problem may be similar to stm32duino/STM32LowPower#71 for witch I proposed a fix: #68 You may have a try

After I try the newest PR, It still can not work, So I use the V1.2 instead of it.

ABOSTM commented 2 years ago

Based on your example I made the following sketch, which works properly on my Nucleo_L476RG: LED is toggling every minutes. It works well with RTCv1.2 as well as v1.3 (even without the patch)

Note that to be sure RTC is resetted and start the test properly, you should unplug/replug power supply.

#include <STM32RTC.h>

/* Get the rtc object */
STM32RTC& rtc = STM32RTC::getInstance();
uint32_t toogle = 0;

void setup() {
  // put your setup code here, to run once:
  pinMode(LED_BUILTIN, OUTPUT);
  Serial.begin(115200);
  rtc.begin(); // initialize RTC 24H format

  uint8_t minutes = rtc.getMinutes();

  minutes = 1 + minutes;  // minutes = (5 - (minutes % 5)) + minutes;
  if (minutes == 60)
  {
    minutes = 0;
  }
  rtc.attachInterrupt(funPtr);
  rtc.setAlarmMinutes(minutes);
  rtc.setAlarmSeconds(0);
  rtc.enableAlarm(rtc.MATCH_MMSS);

}

void loop() {
  // put your main code here, to run repeatedly:
}

void funPtr(void*)
{
  toogle = !toogle;
  digitalWrite(LED_BUILTIN, toogle);
  uint8_t minutes = rtc.getMinutes();

  minutes = 1 + minutes;  // minutes = (5 - (minutes % 5)) + minutes;
  if (minutes == 60)
  {
    minutes = 0;
  }
  rtc.setAlarmMinutes(minutes);
  rtc.setAlarmSeconds(0);
  rtc.enableAlarm(rtc.MATCH_MMSS);
}