2016-01-10 07:49 AM
Hi, I'm trying the learn how to use rtc. can someone help me to understand how to inizialize rtc and how to use timestamp?
i'm using stm32f103 uCthanks :)2016-01-11 12:39 AM
Hi Mr.Cscn,
I'd highly recommend you to start from RTC example under STM32Cube F1 package STM32Cube_FW_F1_V1.3.0\Projects\STM3210E_EVAL\Examples\RTC-Syrine-2016-01-11 06:59 AM
hi Mr.Cscn,
Use the following code-- int main(void) { RCC_APB1PeriphClockCmd( RCC_APB1Periph_BKP | RCC_APB1Periph_PWR , ENABLE); RTC_NVIC_Config(); RTC_Init(); } void RTC_Config(void) { PWR_BackupAccessCmd(ENABLE); BKP_DeInit(); RCC_LSICmd(ENABLE); while(RCC_GetFlagStatus(RCC_FLAG_LSIRDY) == RESET) {} RCC_RTCCLKConfig(RCC_RTCCLKSource_LSI ); RCC_RTCCLKCmd(ENABLE); RTC_WaitForSynchro(); RTC_WaitForLastTask(); RTC_SetPrescaler(32767); RTC_WaitForLastTask(); RTC_ITConfig(RTC_IT_SEC, ENABLE); RTC_WaitForLastTask(); } void RTC_NVIC_Config(void) { NVIC_InitTypeDef NVIC_InitStructure; NVIC_PriorityGroupConfig(NVIC_PriorityGroup_0); NVIC_InitStructure.NVIC_IRQChannel = RTC_IRQn; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0; NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure); RTC_ITConfig(RTC_IT_SEC, ENABLE); } void RTC_Init(void) { if (BKP_ReadBackupRegister(BKP_DR1) != 0xA5A5) { RTC_Configuration(); Time_Adjust(); BKP_WriteBackupRegister(BKP_DR1, 0xA5A5); } else { RTC_WaitForSynchro(); RTC_WaitForLastTask(); PWR_BackupAccessCmd(ENABLE); } return; } void Time_Adjust(void) { u32 counter = 1449100000;//set equl to current unix time stamp RTC_WaitForLastTask(); RTC_SetCounter(counter); RTC_WaitForLastTask(); } void RTC_IRQHandler(void){ if (RTC_GetITStatus(RTC_IT_SEC) != RESET){ RTC_ClearITPendingBit(RTC_IT_SEC); RTC_WaitForLastTask(); } }