2012-09-03 05:47 PM
Hi all,
I am new to programming. I wanted some help regarding rtc coding. I am using stm32l1 discovery board(and IAR workbench), and want to generate interrupt after every 2 mins. I think using timers for this will be tricky. I tried one vague attempt using std periph examples, and obviously it din work.. I donno the format that i should give for 2 mins interrupt generation. void RTC_Config(void) { RTC_InitTypeDef RTC_InitStructure; RTC_TimeTypeDef RTC_TimeStruct; /* Enable the PWR clock */ RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR, ENABLE); /* Allow access to RTC */ PWR_RTCAccessCmd(ENABLE); /* Reset RTC Domain */ RCC_RTCResetCmd(ENABLE); RCC_RTCResetCmd(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 */ 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_BIN, &RTC_TimeStruct); /* Enable the RTC Clock */ RCC_RTCCLKCmd(ENABLE); /* Wait for RTC APB registers synchronisation */ RTC_WaitForSynchro(); } /** * @brief Configures the RTC Alarm. * @param None * @retval None */ void RTC_AlarmConfig(void) { EXTI_InitTypeDef EXTI_InitStructure; RTC_AlarmTypeDef RTC_AlarmStructure; NVIC_InitTypeDef NVIC_InitStructure; /* 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_Alarm_IRQn; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0; NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure); /* Set the alarmA Masks */ RTC_AlarmStructure.RTC_AlarmMask = RTC_AlarmMask_NONE; RTC_SetAlarm(RTC_Format_BIN, RTC_Alarm_A, &RTC_AlarmStructure); RTC_AlarmStructure.RTC_AlarmTime.RTC_Minutes = 2; /* Enable AlarmA interrupt */ RTC_ITConfig(RTC_IT_ALRA, ENABLE); /* Enable the alarmA */ RTC_AlarmCmd(RTC_Alarm_A, DISABLE); } Any help is highly appreciated. Thanks2012-09-04 03:26 AM
hi all..,
Or can anyone suggest me any alternative to generate interrupt after each 2mins??2012-09-04 05:17 AM
Without timer or rtc, this is hardly possible.
However, a simpler approach is to use the Systick timer. Configure it, for instance, for one interrupt each second, and count up the seconds. A SysTick example application is provided in the PeripheralDriver libs.