cancel
Showing results for 
Search instead for 
Did you mean: 

RTC cause main code stop working

hamed_solar
Associate II
Posted on October 21, 2017 at 01:06

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

I use this code for setup rtc with alarm . when interrupt of rtc is running the other section of code stop working but the interrupt routin of rtc  is working and turn off and on one buzzer every seconds.

How can I correct this?

 

/**

  * @brief  Configure the RTC peripheral by selecting the clock source.

  * @param  None

  * @retval None

  */

static void RTC_Config1(void)

{

  RTC_InitTypeDef  RTC_InitStructure;

  RTC_TimeTypeDef  RTC_TimeStruct;

//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);

    RCC_LSEDriveConfig(RCC_LSEDrive_High);

  /* 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);

///////////////////////////////////////////////////////////////////////////////////////////////////////

}

/**

  * @brief  Configures the RTC Alarm.

  * @param  None

  * @retval None

  */

static void RTC_AlarmConfig(void)

{

  EXTI_InitTypeDef EXTI_InitStructure;

  RTC_AlarmTypeDef RTC_AlarmStructure;

  NVIC_InitTypeDef NVIC_InitStructure;

  RTC_AlarmStructInit(&RTC_AlarmStructure);

    

  /* EXTI configuration */

  EXTI_ClearITPendingBit(EXTI_Line17);

  EXTI_InitStructure.EXTI_Line = EXTI_Line17;

  EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;

  EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising;

  EXTI_InitStructure.EXTI_LineCmd = ENABLE;

  EXTI_Init(&EXTI_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);

 

  /* Set AlarmA subseconds and enable SubSec Alarm : generate 8 interripts per Second */

  RTC_AlarmSubSecondConfig(RTC_Alarm_A, 0xFF, RTC_AlarmSubSecondMask_SS14_5);

  /* Enable AlarmA interrupt */

  RTC_ITConfig(RTC_IT_ALRA, ENABLE);

          /* Enable the alarm  A */

  RTC_AlarmCmd(RTC_Alarm_A, ENABLE);

//     /* Wait for RTC APB registers synchronisation */

    RTC_WaitForSynchro();

        

         /* Enable the RTC Clock */

  RCC_RTCCLKCmd(ENABLE);

}

Regards,

#stop-work #lse-rtc #rtc
1 REPLY 1
hamed_solar
Associate II
Posted on October 21, 2017 at 22:56

I insert 'EXTI_ClearITPendingBit(EXTI_Line17);' in the interrupt routine of rtc and the main code can continue its working .

But the new problem is the

incorrect

interval between the calling of interrupt routine . It must be executed for each second but now it cant.

I do not know the reason for this objection

.

void RTC_IRQHandler(void)

{

  if(RTC_GetITStatus(RTC_IT_ALRA) != RESET)

  {

        

    RTC_ClearITPendingBit(RTC_IT_ALRA);

    EXTI_ClearITPendingBit(EXTI_Line17);

        GPIOB->ODR ^= GPIO_ODR_5 ; /* Toggle Green LED */

  }

}

Please help me.

Regards