블루 브리지 컵 내장 - RTC

6099 단어 STM32stm32
기초 지식
4
  • 6-STM32 펌웨어 라이브러리 코드 V3.버전 5\stm32f10xstdperiph_lib\STM32F10x_StdPeriph_Lib_V3.5.0\Project\STM32F10x_StdPeriph_Examples\RTC\LSI_Calib

  • 2. 주요 코드rtc.c
    #include "rtc.h"
    
    void RTC_Init(void)
    {
    	RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR | RCC_APB1Periph_BKP, ENABLE);
    	
    	/* Allow access to BKP Domain */
    	PWR_BackupAccessCmd(ENABLE);
    	
    	/* Reset Backup Domain */
    	BKP_DeInit();
    	
    	/* Enable the LSI OSC */
    	RCC_LSICmd(ENABLE);
    	/* Wait till LSI is ready */
    	while (RCC_GetFlagStatus(RCC_FLAG_LSIRDY) == RESET)
    	{}
    	/* Select the RTC Clock Source */
    	RCC_RTCCLKConfig(RCC_RTCCLKSource_LSI);
    	
    	/* Enable RTC Clock */
    	RCC_RTCCLKCmd(ENABLE);
    	
    	/* Wait for RTC registers synchronization */
    	RTC_WaitForSynchro();
    	
    	/* Wait until last write operation on RTC registers has finished */
    	RTC_WaitForLastTask();
    	
    	/* Enable the RTC Second */
    	RTC_ITConfig(RTC_IT_SEC, ENABLE);
    	
    	/* Wait until last write operation on RTC registers has finished */
    	RTC_WaitForLastTask();
    	
    	/* Set RTC prescaler: set RTC period to 1sec */
    	RTC_SetPrescaler(40000);
    	
    	/* Wait until last write operation on RTC registers has finished */
    	RTC_WaitForLastTask();
    }
    
    
    rtc.h
    #ifndef  __RTC_H_
    #define  __RTC_H_
    
    #include "stm32f10x.h"
    
    void RTC_Init(void);
    
    
    #endif
    
    
    main.h
    void RTC_IRQHandler(void)
    {
      if (RTC_GetITStatus(RTC_IT_SEC) != RESET)
      {
    
    	/*           */
        RTC_ClearITPendingBit(RTC_FLAG_SEC);
      }
    }
    

    3. 문헌 참고 1.Zach_z 작성자 코드

    좋은 웹페이지 즐겨찾기