stm32f103c8t6 芯片内部RTC初始化函数
时间: 2023-09-05 10:08:39 浏览: 102
以下是stm32f103c8t6芯片内部RTC初始化函数的示例代码:
```c
#include "stm32f10x.h"
#include "stm32f10x_rtc.h"
#include "stm32f10x_pwr.h"
#include "stm32f10x_bkp.h"
RTC_InitTypeDef RTC_InitStructure;
void RTC_Configuration(void)
{
/* Enable the PWR clock */
RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR, ENABLE);
/* Allow access to BKP Domain */
PWR_BackupAccessCmd(ENABLE);
/* Reset Backup Domain */
BKP_DeInit();
/* 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);
/* Enable the RTC Clock */
RCC_RTCCLKCmd(ENABLE);
/* Wait for RTC APB registers synchronisation */
RTC_WaitForSynchro();
/* 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);
/* Enable the RTC Alarm interrupt */
RTC_ITConfig(RTC_IT_ALR, ENABLE);
/* Enable the alarm */
RTC_AlarmCmd(RTC_Alarm_A, ENABLE);
}
int main(void)
{
/* RTC Configuration */
RTC_Configuration();
while (1)
{
/* Do something */
}
}
```
在此示例代码中,我们首先使能了PWR时钟,使能了BKP域的访问,并重置了BKP域。然后,我们使能了LSE OSC,并等待LSE准备好。接着,我们选择了RTC时钟源并使能了RTC时钟,并等待RTC APB寄存器的同步。然后,我们配置了RTC的数据寄存器和预分频器,并使能了RTC闹钟中断和闹钟。最后,在主循环中执行其他操作。
阅读全文