zhyinch
2020-03-08 9607804a0c06eaf5c14f4089bf04ac2a52986eaa
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#include "RTC.h"
 
 
void RTC_SET_ALARM(u32 sec)
{
    //DEBUG_COM_STREAM("-??-",NULL);
    RTC_SetAlarm(RTC_GetCounter()+sec);
    //DEBUG_COM_STREAM("-??1-",NULL);
    RTC_WaitForLastTask();
    //DEBUG_COM_STREAM("-??2-",NULL);
    RTC_ITConfig(RTC_FLAG_ALR,ENABLE);
}
 
void RTC_Configuration(uint16_t interval)
{
    EXTI_InitTypeDef EXTI_InitStructure;
    
    /* Enable PWR and BKP clocks */
    RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR | RCC_APB1Periph_BKP, ENABLE);
 
    /* Allow access to BKP Domain */
    PWR_BackupAccessCmd(ENABLE);
 
    /* Reset Backup Domain */
    //BKP_DeInit();
 
    RCC_LSICmd(ENABLE);
    /* Enable LSE */
    //RCC_LSEConfig(RCC_LSE_ON);
    /* Wait till LSE is ready */
    while (RCC_GetFlagStatus(RCC_FLAG_LSIRDY) == RESET){}
 
    /* Select LSE as 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();
        
    RTC_ITConfig(RTC_IT_ALR,ENABLE); //?? RTC ???  
        RTC_WaitForLastTask();
    /* Set RTC prescaler: set RTC period to 1sec */
    RTC_SetPrescaler(interval); /* RTC period = RTCCLK/RTC_PR = (32.768 KHz)/(32767+1) */
 
    /* Wait until last write operation on RTC registers has finished */
    RTC_WaitForLastTask();
    RTC_SET_ALARM(1);
    
    //RTCÍⲿÖжÏʹÄÜ
    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); 
    
}