AnsweredAssumed Answered

RTC not interrupting every seconds

Question asked by shams.hamed on Oct 16, 2017
Latest reply on Oct 19, 2017 by shams.hamed

Hi

I was running RTC with stm32f051. I use cmsis and using LSE(32.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

Outcomes