@@ -24,21 +24,28 @@ void rtc_init(void) {
24
24
25
25
BKP_DeInit (); // Reset Backup Domain
26
26
27
+ // Uncomment these lines if you use the LSE
27
28
// Enable LSE and wait till it's ready
28
- RCC_LSEConfig (RCC_LSE_ON );
29
- while (RCC_GetFlagStatus (RCC_FLAG_LSERDY ) == RESET ) {}
30
-
31
- RCC_RTCCLKConfig (RCC_RTCCLKSource_LSE ); // Select LSE as RTC Clock Source
29
+ //RCC_LSEConfig(RCC_LSE_ON);
30
+ //while (RCC_GetFlagStatus(RCC_FLAG_LSERDY) == RESET) {}
31
+ //RCC_RTCCLKConfig(RCC_RTCCLKSource_LSE); // Select LSE as RTC Clock Source
32
32
33
+ // Uncomment these lines if you use the LSI
34
+ // Enable LSI and wait till it's ready
35
+ RCC_LSICmd (ENABLE );
36
+ while (RCC_GetFlagStatus (RCC_FLAG_LSIRDY ) == RESET ) {}
37
+ RCC_RTCCLKConfig (RCC_RTCCLKSource_LSI ); // Select LSI as RTC Clock Source
38
+
33
39
RCC_RTCCLKCmd (ENABLE ); // Enable RTC Clock
34
40
35
41
RTC_WaitForSynchro (); // Wait for RTC registers synchronization
36
42
37
43
RTC_WaitForLastTask (); // Wait until last write operation on RTC registers has finished
38
44
39
45
// Set RTC period to 1 sec
40
- // RTC period = RTCCLK/RTC_PR = (32.768 KHz)/(32767+1)
41
- RTC_SetPrescaler (32767 );
46
+ // For LSE: prescaler = RTCCLK/RTC period = 32768Hz/1Hz = 32768
47
+ // For LSI: prescaler = RTCCLK/RTC period = 40000Hz/1Hz = 40000
48
+ RTC_SetPrescaler (39999 );
42
49
43
50
RTC_WaitForLastTask (); // Wait until last write operation on RTC registers has finished
44
51
0 commit comments