hallo zusamen ich bin ganz ganz anfanger ich versuchen mit STM32 RTC ein ganz ein fache uhr 0 bis 12 realesieren ich weis garnicht wie kann man das machen konte jemanden mir hinweis dazu geben
Stm Library da gibt es viele Projektbeispiele in C. Da würde ich mich an deiner Stelle mal durchblättern. mfg Jan
Danke jan ich konte die folgende code von Stm Library ich habe damit nur die RTC konfiguriert und die secunde erzeugt aber das ist nicht alles ich weis dass ich ein main funktin brauche und wie kann ich die folgende mit main funtion ausfuhren void RTC_Init(void) { /* CK_RTC clock selection */ RCC_APB1PeriphClockCmd( RCC_APB1Periph_PWR | RCC_APB1Periph_BKP, ENABLE ); PWR_BackupAccessCmd( ENABLE ); /* Allow access to BKP Domain */ BKP_DeInit(); /* Reset Backup Domain */ RCC_LSEConfig( RCC_LSE_ON ); /* Enable the LSE OSC */ while (RCC_GetFlagStatus(RCC_FLAG_LSERDY) == RESET) {} /* Wait till LSE is ready */ RCC_RTCCLKConfig( RCC_RTCCLKSource_LSE ); /* Select the RTC Clock Source RCC_RTCCLKCmd( ENABLE ); /* Enable the RTC Clock */ RTC_WaitForSynchro(); /* Wait for RTC registers synchronization */ /* Wait until last write operation on RTC registers has finished */ RTC_WaitForLastTask(); RTC_ITConfig( RTC_IT_SEC, ENABLE ); /* Enable the RTC Second interrupt */ /* Wait until last write operation on RTC registers has finished */ RTC_WaitForLastTask(); /* Set RTC prescaler: set RTC period to 1sec */ /* RTC period = RTCCLK/RTC_PR = (32.768 KHz)/(32767+1) */ RTC_SetPrescaler( 32767 ); /* Wait until last write operation on RTC registers has finished */ RTC_WaitForLastTask(); } RTC - ISR > void RTC_IRQHandler(void) > { > if (RTC_GetITStatus(RTC_IT_SEC) != RESET) > { > if (getClock_state()!=0) > { > toogleGreen(); > DRAW_DisplayTime( 30, 30 ); > } > } > /* Clear the RTC Second interrupt */ > RTC_ClearITPendingBit(RTC_IT_SEC); }
Oje, das kann ja keiner lesen!
1 | void RtcConfig(void) |
2 | {
|
3 | NVIC_InitTypeDef NVIC_InitStructure; |
4 | EXTI_InitTypeDef EXTI_InitStructure; |
5 | |
6 | /* Configure EXTI Line17(RTC Alarm) to generate an interrupt on rising edge */
|
7 | EXTI_ClearITPendingBit(EXTI_Line17); |
8 | EXTI_InitStructure.EXTI_Line = EXTI_Line17; |
9 | EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt; |
10 | EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising; |
11 | EXTI_InitStructure.EXTI_LineCmd = ENABLE; |
12 | EXTI_Init(&EXTI_InitStructure); |
13 | |
14 | /* 2 bits for Preemption Priority and 2 bits for Sub Priority */
|
15 | //NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);
|
16 | |
17 | NVIC_InitStructure.NVIC_IRQChannel = RTCAlarm_IRQn; |
18 | NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0; |
19 | NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1; |
20 | NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; |
21 | NVIC_Init(&NVIC_InitStructure); |
22 | |
23 | /* Enable PWR and BKP clock */
|
24 | RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR | RCC_APB1Periph_BKP, ENABLE); |
25 | |
26 | /* RTC clock source configuration ------------------------------------------*/
|
27 | /* Allow access to BKP Domain */
|
28 | PWR_BackupAccessCmd(ENABLE); |
29 | |
30 | /* Reset Backup Domain */
|
31 | BKP_DeInit(); |
32 | |
33 | /* Enable the LSE OSC */
|
34 | RCC_LSEConfig(RCC_LSE_ON); |
35 | /* Wait till LSE is ready */
|
36 | while(RCC_GetFlagStatus(RCC_FLAG_LSERDY) == RESET) |
37 | {
|
38 | }
|
39 | |
40 | /* Select the RTC Clock Source */
|
41 | RCC_RTCCLKConfig(RCC_RTCCLKSource_LSE); |
42 | |
43 | /* Enable the RTC Clock */
|
44 | RCC_RTCCLKCmd(ENABLE); |
45 | |
46 | /* RTC configuration -------------------------------------------------------*/
|
47 | /* Wait for RTC APB registers synchronisation */
|
48 | RTC_WaitForSynchro(); |
49 | RTC_WaitForLastTask(); |
50 | |
51 | /* Set the RTC time base to 1s */
|
52 | RTC_SetPrescaler(32767); |
53 | /* Wait until last write operation on RTC registers has finished */
|
54 | RTC_WaitForLastTask(); |
55 | |
56 | /* Enable the RTC Alarm interrupt */
|
57 | RTC_ITConfig(RTC_IT_ALR, ENABLE); |
58 | /* Wait until last write operation on RTC registers has finished */
|
59 | RTC_WaitForLastTask(); |
60 | |
61 | rStatus.clockStatus = RTC_CLOCK_ON; |
62 | }
|
Ok, ergänzend: --> RTC Alarm ist angeschaltet und sollte in der main refreshed werden, bzw die RTC flags im INT gelöscht werden. Selbstverständlich IRQ Fkt. eintragen.
1 | void RtcAlarmStart(bool init) |
2 | {
|
3 | RTC_WaitForLastTask(); |
4 | if(init) {RtcConfig();} |
5 | |
6 | /* Wait till RTC Second event occurs */
|
7 | RTC_ClearFlag(RTC_FLAG_SEC); |
8 | while(RTC_GetFlagStatus(RTC_FLAG_SEC) == RESET); |
9 | |
10 | /* Alarm in 1 second */
|
11 | RTC_WaitForLastTask(); |
12 | RTC_SetAlarm(RTC_GetCounter() + RTC_1SEC); |
13 | /* Wait until last write operation on RTC registers has finished */
|
14 | RTC_WaitForLastTask(); |
15 | RTC_WaitForSynchro(); |
16 | |
17 | rStatus.alarmStatus = RTC_ALARM_ON; |
18 | }
|
19 | |
20 | void RtcAlarmReload(_RTC_DURATION dur) |
21 | {
|
22 | RTC_SetAlarm(RTC_GetCounter() + dur); |
23 | RTC_WaitForLastTask(); |
24 | }
|
--> Abfrage der aktuellen TICKS über STM library --> RTC_GetCounter() -->µC wird über EXTI17 aus StopMode geweckt, bzw bei StanBy Reset, also EXTI17 weglassen oder nit Viel Spass, ich hoffe ich habe nix vergessen ansonsten fragen ! Gruss und moin.
ein frage RTC lost ein secunde interrupt( Alarm pro secunde) an welche pin kann ich die secunde interrupt haben ist RTC mit ein bistimte pin verbunden oder kann mann die belibig mit ein pin verbinden von datasheet weis ich die ist mit TAMPER-RTC/ ALARM/SECOND OUT verbuden
Bitte melde dich an um einen Beitrag zu schreiben. Anmeldung ist kostenlos und dauert nur eine Minute.
Bestehender Account
Schon ein Account bei Google/GoogleMail? Keine Anmeldung erforderlich!
Mit Google-Account einloggen
Mit Google-Account einloggen
Noch kein Account? Hier anmelden.