./. schrieb:
>
> Das Beispiel moechte ich mal sehen.
>
> An den interessanten Stellen haben die Examples von ST immer aufgehoert.
Was sind denn für dich die interessanten Stellen?
das hier stammt direkt aus der StdLib:
1 | if (BKP_ReadBackupRegister(BKP_DR1) != 0xA5A5)
|
2 | {
|
3 | /* Backup data register value is not correct or not yet programmed (when
|
4 | the first time the program is executed) */
|
5 |
|
6 | printf("\r\n\n RTC not yet configured....");
|
7 |
|
8 | /* RTC Configuration */
|
9 | RTC_Configuration();
|
10 |
|
11 | printf("\r\n RTC configured....");
|
12 |
|
13 | /* Adjust time by values entered by the user on the hyperterminal */
|
14 | Time_Adjust();
|
15 |
|
16 | BKP_WriteBackupRegister(BKP_DR1, 0xA5A5);
|
17 | }
|
18 | else
|
19 | {
|
20 | /* Check if the Power On Reset flag is set */
|
21 | if (RCC_GetFlagStatus(RCC_FLAG_PORRST) != RESET)
|
22 | {
|
23 | printf("\r\n\n Power On Reset occurred....");
|
24 | }
|
25 | /* Check if the Pin Reset flag is set */
|
26 | else if (RCC_GetFlagStatus(RCC_FLAG_PINRST) != RESET)
|
27 | {
|
28 | printf("\r\n\n External Reset occurred....");
|
29 | }
|
30 |
|
31 | printf("\r\n No need to configure RTC....");
|
32 | /* Wait for RTC registers synchronization */
|
33 | RTC_WaitForSynchro();
|
34 |
|
35 | /* Enable the RTC Second */
|
36 | RTC_ITConfig(RTC_IT_SEC, ENABLE);
|
37 | /* Wait until last write operation on RTC registers has finished */
|
38 | RTC_WaitForLastTask();
|
39 | }
|
und hier noch die dazu gehörigen Initialisierung (aus der gleichen
Datei)
1 | void RTC_Configuration(void)
|
2 | {
|
3 | /* Enable PWR and BKP clocks */
|
4 | RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR | RCC_APB1Periph_BKP, ENABLE);
|
5 |
|
6 | /* Allow access to BKP Domain */
|
7 | PWR_BackupAccessCmd(ENABLE);
|
8 |
|
9 | /* Reset Backup Domain */
|
10 | BKP_DeInit();
|
11 |
|
12 | /* Enable LSE */
|
13 | RCC_LSEConfig(RCC_LSE_ON);
|
14 | /* Wait till LSE is ready */
|
15 | while (RCC_GetFlagStatus(RCC_FLAG_LSERDY) == RESET)
|
16 | {}
|
17 |
|
18 | /* Select LSE as RTC Clock Source */
|
19 | RCC_RTCCLKConfig(RCC_RTCCLKSource_LSE);
|
20 |
|
21 | /* Enable RTC Clock */
|
22 | RCC_RTCCLKCmd(ENABLE);
|
23 |
|
24 | /* Wait for RTC registers synchronization */
|
25 | RTC_WaitForSynchro();
|
26 |
|
27 | /* Wait until last write operation on RTC registers has finished */
|
28 | RTC_WaitForLastTask();
|
29 |
|
30 | /* Enable the RTC Second */
|
31 | RTC_ITConfig(RTC_IT_SEC, ENABLE);
|
32 |
|
33 | /* Wait until last write operation on RTC registers has finished */
|
34 | RTC_WaitForLastTask();
|
35 |
|
36 | /* Set RTC prescaler: set RTC period to 1sec */
|
37 | RTC_SetPrescaler(32767); /* RTC period = RTCCLK/RTC_PR = (32.768 KHz)/(32767+1) */
|
38 |
|
39 | /* Wait until last write operation on RTC registers has finished */
|
40 | RTC_WaitForLastTask();
|
41 | }
|
Damit hat man einen Zähler, der alle Sekunde um 1 erhöht wird.
Was man jetzt damit macht, z.B. das ganze in ein Datum umrechnet, das
bleibt jedem selbst überlassen.
Oder man muss halt schauen wie andere das gelöst haben. Das hat aber
nicht mit der Funktion der RTC an sich zu tun.