cancel
Showing results for 
Search instead for 
Did you mean: 

RTC not interrupting every seconds

hamed_solar
Associate II
Posted on October 16, 2017 at 15:52

Hi

I was running RTC with stm32f I use cmsis and using LSE(768 khz) for rtc.

I want to trig the RTC_IRQ on each second. How can I active it ? Its my code for adjusting rtc

static void RTC_Config(void) {  RTC_TimeTypeDef RTC_TimeStruct;  RTC_InitTypeDef RTC_InitStructure;  NVIC_InitTypeDef NVIC_InitStructure;    /* Enable the PWR clock */  RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR, ENABLE);      /* Allow access to RTC */  PWR_BackupAccessCmd(ENABLE);    /* Reset RTC Domain */  RCC_BackupResetCmd(ENABLE);  RCC_BackupResetCmd(DISABLE);    /* Enable the LSE OSC */  RCC_LSEConfig(RCC_LSE_ON);     /* Wait till LSE is ready */   while(RCC_GetFlagStatus(RCC_FLAG_LSERDY) == RESET)  {}    /* Select the RTC Clock Source */  RCC_RTCCLKConfig(RCC_RTCCLKSource_LSE);      /* Configure the RTC data register and RTC prescaler */  /* ck_spre(1Hz) = RTCCLK(LSI) /(AsynchPrediv + 1)*(SynchPrediv + 1)*/  RTC_InitStructure.RTC_AsynchPrediv = 0x7F;  RTC_InitStructure.RTC_SynchPrediv = 0xFF;  RTC_InitStructure.RTC_HourFormat = RTC_HourFormat_24;  RTC_Init(&RTC_InitStructure);    /* Set the time to 00h 00mn 00s AM */  RTC_TimeStruct.RTC_H12 = RTC_H12_AM;  RTC_TimeStruct.RTC_Hours = 0x00;  RTC_TimeStruct.RTC_Minutes = 0x00;  RTC_TimeStruct.RTC_Seconds = 0x00;   RTC_SetTime(RTC_Format_BCD, &RTC_TimeStruct);   ///////////////////////////////////////////////////////////////////////////////////////////////////////    /* Enable AlarmA interrupt */  RTC_ITConfig(RTC_IT_TS, ENABLE);        /* Enable the RTC Alarm Interrupt */  NVIC_InitStructure.NVIC_IRQChannel = RTC_IRQn;  NVIC_InitStructure.NVIC_IRQChannelPriority = 0;  NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;  NVIC_Init(&NVIC_InitStructure);    RCC_RTCCLKCmd(ENABLE); // Enable RTC  RTC_WaitForSynchro(); }�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?

Regards

hamed

#stm32 #rtc

Note: this post was migrated and contained many threaded conversations, some content may be missing.
8 REPLIES 8
john doe
Lead
Posted on October 16, 2017 at 19:30

0690X00000608clQAA.png
Posted on October 16, 2017 at 19:37

Thanks for reply

How can I define this mask combination? Can you give the code?

Posted on October 16, 2017 at 20:00

I don't use the SPL, I use the HAL.  In the HAL its part of your alarm initialization struct.  Probably in the SPL, too.  Read the app note and look at how the alarm struct is defined in the header file you use.

Posted on October 16, 2017 at 22:32

I use this code for enabling alarm for every one second. but it does not call the RTC_IRQHandler()

static void RTC_AlarmConfig(void)

{

//  EXTI_InitTypeDef EXTI_InitStructure;

  RTC_AlarmTypeDef RTC_AlarmStructure;

//  NVIC_InitTypeDef NVIC_InitStructure;

    

  /* Enable the RTC Alarm Interrupt */

  NVIC_InitStructure.NVIC_IRQChannel = RTC_IRQn;

  NVIC_InitStructure.NVIC_IRQChannelPriority = 0;

  NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;

  NVIC_Init(&NVIC_InitStructure);

 

  /* Set the alarmA Masks */

  RTC_AlarmStructure.RTC_AlarmMask = RTC_AlarmMask_All;

  RTC_SetAlarm(RTC_Format_BCD, RTC_Alarm_A, &RTC_AlarmStructure);

  RTC_AlarmSubSecondConfig(RTC_Alarm_A, 0x1, RTC_AlarmSubSecondMask_SS14);

  /* Enable AlarmA interrupt */

   RTC_ITConfig(RTC_IT_ALRA, ENABLE);

    

    

}
Posted on October 17, 2017 at 00:34

Isn't there a specific 1 Hz interrupt, try doing an alarm at multiple seconds in the future.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Posted on October 17, 2017 at 14:02

I realize that I cant set the alarm .I think it is the reason that rtc interrupt dont trig. for example I set the below variable:

RTC_AlarmStructure.RTC_AlarmTime.RTC_Hours = 5;

RTC_AlarmStructure.RTC_AlarmTime.RTC_Minutes = 5;

RTC_AlarmStructure.RTC_AlarmTime.RTC_Seconds = 5;

But  the returned values of them is zero.

Its my code for set time and alarm value.

 

void RTC_TimeRegulate(void)

 

{

 

  RTC_TimeTypeDef RTC_TimeStructure;

 

  RTC_AlarmTypeDef  RTC_AlarmStructure;

 

 

 

 

 

  printf('\n\r==============Time Settings=====================================\n\r');

 

    

 

  RTC_TimeStructure.RTC_H12     = RTC_H12_AM;

 

 

    RTC_TimeStructure.RTC_Hours = 1;

 

 

    RTC_TimeStructure.RTC_Minutes = 1;

 

 

    RTC_TimeStructure.RTC_Seconds = 5;

 

  }

 

 

 

  /* Configure the RTC time register */

 

  if(RTC_SetTime(RTC_Format_BIN, &RTC_TimeStructure) == ERROR)

 

  {

 

    printf('\n\r>> !! RTC Set Time failed. !! <<\n\r');

 

  }

 

  else

 

  {

 

    printf('\n\r>> !! RTC Set Time success. !! <<\n\r');

 

    RTC_TimeShow();

 

    /* Indicator for the RTC configuration */

 

    RTC_WriteBackupRegister(RTC_BKP_DR0, BKP_VALUE);

 

           

 

  }

 

 

  /* Disable the Alarm A */

 

  RTC_AlarmCmd(RTC_Alarm_A, DISABLE);

 

 

  printf('\n\r==============Alarm A Settings=====================================\n\r');

 

  RTC_AlarmStructure.RTC_AlarmTime.RTC_H12 = RTC_H12_AM;

 

 

   RTC_AlarmStructure.RTC_AlarmTime.RTC_Hours = 1;

 

 

    RTC_AlarmStructure.RTC_AlarmTime.RTC_Minutes = 1;

 

 

    RTC_AlarmStructure.RTC_AlarmTime.RTC_Seconds = 10;

 

 

 

  /* Set the Alarm A */

 

  RTC_AlarmStructure.RTC_AlarmDateWeekDaySel = RTC_AlarmDateWeekDaySel_Date;

 

  RTC_AlarmStructure.RTC_AlarmDateWeekDay = RTC_Weekday_Monday;    

 

  RTC_AlarmStructure.RTC_AlarmMask =RTC_AlarmMask_DateWeekDay;//RTC_AlarmMask_All;// RTC_AlarmMask_DateWeekDay;

 

 

  /* Configure the RTC Alarm A register */

 

  RTC_SetAlarm(RTC_Format_BIN, RTC_Alarm_A, &RTC_AlarmStructure);

 

  printf('\n\r>> !! RTC Set Alarm success. !! <<\n\r');

 

  RTC_AlarmShow();

 

 

  /* Enable the RTC Alarm A Interrupt */

 

  RTC_ITConfig(RTC_IT_ALRA, ENABLE);

 

   

 

  /* Enable the alarm  A */

 

  RTC_AlarmCmd(RTC_Alarm_A, ENABLE);

 

}

 

 

void RTC_AlarmShow(void)

 

{

 

  RTC_AlarmTypeDef  RTC_AlarmStructure;

 

  /* Get the current Alarm */

 

  RTC_GetAlarm(RTC_Format_BIN, RTC_Alarm_A, &RTC_AlarmStructure);

 

  printf('\n\r  The current alarm is :  %0.2d:%0.2d:%0.2d \n\r', RTC_AlarmStructure.RTC_AlarmTime.RTC_Hours, RTC_AlarmStructure.RTC_AlarmTime.RTC_Minutes, RTC_AlarmStructure.RTC_AlarmTime.RTC_Seconds);

 

}

Regards,

Hamed

Posted on October 17, 2017 at 19:31

How can I adjust alarm correctly?

Posted on October 17, 2017 at 21:14

printf('\n\r==============Alarm A Settings=====================================\n\r');

 

RTC_AlarmStructure.RTC_AlarmTime.RTC_H12 = RTC_H12_AM;

 

RTC_AlarmStructure.RTC_AlarmTime.RTC_Hours = 1;

 

RTC_AlarmStructure.RTC_AlarmTime.RTC_Minutes = 1;

 

RTC_AlarmStructure.RTC_AlarmTime.RTC_Seconds = 10;

 

I think you need to readAN3371