Forum: Mikrocontroller und Digitale Elektronik RTC Initialisierung auf STM32F4 geht nicht :-(


von Denis S. (h44656e)


Lesenswert?

Hallo zusammen,

ich versuche grade auf einem STM32F4 Discovery  den RTC ans Laufen zu 
bringen. Vergeblich!!!
Das Programm verlässt die schleife einfach nicht!
1
  /* Wait till LSE is ready */
2
  while(RCC_GetFlagStatus(RCC_FLAG_LSERDY) == RESET)
3
  {
4
  }
Man muss auch dazu sagen das das Board keine BackUp Batterie hat.

Also die Verzweiflung ist sehr groß!!!
Gruß
Denis
p.s.
ich muss dazu sagen das das Gesamte Programm in C++ geschrieben wird.
die h – Datei mit der
1
 void RTC_INIT(void)
 wird allerdings über
extern „c“ eingebunden.

Code:
1
void RTC_INIT(void)
2
{
3
4
  /* Enable the PWR clock */
5
  RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR , ENABLE);
6
7
  /* Allow access to RTC */
8
  PWR_BackupAccessCmd(ENABLE);
9
10
  /* Reset RTC Domain */
11
  RCC_BackupResetCmd(ENABLE);
12
  RCC_BackupResetCmd(DISABLE);
13
  
14
  
15
  /* Enable the LSE OSC */
16
  RCC_LSEConfig(RCC_LSE_ON);
17
18
  /* Wait till LSE is ready */
19
  while(RCC_GetFlagStatus(RCC_FLAG_LSERDY) == RESET)
20
  {
21
  }
22
23
  /* Select the RTC Clock Source */
24
  RCC_RTCCLKConfig(RCC_RTCCLKSource_LSE);
25
26
  /* Configure the RTC data register and RTC prescaler */
27
  RTC_InitStructure.RTC_AsynchPrediv = 0x7F;
28
  RTC_InitStructure.RTC_SynchPrediv  = 0xFF;
29
  RTC_InitStructure.RTC_HourFormat   = RTC_HourFormat_24;
30
  RTC_Init(&RTC_InitStructure);
31
32
  /* Set the time to 00h 00mn 00s AM */
33
  RTC_TimeStruct.RTC_H12     = RTC_H12_AM;
34
  RTC_TimeStruct.RTC_Hours   = 0x00;
35
  RTC_TimeStruct.RTC_Minutes = 0x00;
36
  RTC_TimeStruct.RTC_Seconds = 0x00;
37
  RTC_SetTime(RTC_Format_BCD, &RTC_TimeStruct);
38
39
}

von Jörn K. (joern)


Lesenswert?

Weil du den externen Quarz (LSE) verwendest und lt. Schaltplan ist kein 
32kHz Quarz bestückt.

Alternativ kannst du den internen 32kHz RC-Oszillator testen (LSI).

von Denis S. (h44656e)


Lesenswert?

Danke für die Antwort.
Leider komme ich immer noch nicht weiter.
Ich habe den Code so abgeändert:
1
void RTC_INIT(void)
2
{
3
4
  /* Enable the PWR clock */
5
  RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR , ENABLE);
6
7
  /* Allow access to RTC */
8
  PWR_BackupAccessCmd(ENABLE);
9
10
  /* Reset RTC Domain */
11
  RCC_BackupResetCmd(ENABLE);
12
  RCC_BackupResetCmd(DISABLE);
13
14
15
  /* Enable the LSI OSC */
16
  RCC_LSICmd(ENABLE);
17
18
19
  /* Wait till LSI is ready */
20
  while(RCC_GetFlagStatus(RCC_FLAG_LSIRDY) == RESET)
21
  {
22
  }
23
24
  /* Select the RTC Clock Source */
25
  RCC_RTCCLKConfig(RCC_RTCCLKSource_LSI);
26
27
  /* Configure the RTC data register and RTC prescaler */
28
  RTC_InitStructure.RTC_AsynchPrediv = 0x7F;
29
  RTC_InitStructure.RTC_SynchPrediv  = 0xFF;
30
  RTC_InitStructure.RTC_HourFormat   = RTC_HourFormat_24;
31
  RTC_Init(&RTC_InitStructure);
32
33
  /* Set the time to 00h 00mn 00s AM */
34
  RTC_TimeStruct.RTC_H12     = RTC_H12_AM;
35
  RTC_TimeStruct.RTC_Hours   = 0x03;
36
  RTC_TimeStruct.RTC_Minutes = 0x03;
37
  RTC_TimeStruct.RTC_Seconds = 0x03;
38
  RTC_SetTime(RTC_Format_BCD, &RTC_TimeStruct);
39
40
41
}
An dieser Stelle versuche ich die Zeit auszulesen:
1
char* dat_time::getTimeString()
2
{
3
4
  RTC_TimeTypeDef  RTC_TimeStruct;
5
  RTC_GetTime(RTC_Format_BCD, &RTC_TimeStruct );
6
  sprintf(buffer, "xx2 %02u:%02u:%02u", RTC_TimeStruct.RTC_Hours,RTC_TimeStruct.RTC_Minutes,RTC_TimeStruct.RTC_Seconds);
7
  return buffer;
8
9
}

Dabei tickt die Uhr nicht :-(


Ich weiß dass es schnell albern werden kann, aber vielleicht kann mir 
jemand weiter helfen.

Gruß
Denis

von Jörn K. (joern)


Angehängte Dateien:

Lesenswert?

Wie wäre es noch mit einem:

  /* Enable the RTC Clock */
  RCC_RTCCLKCmd(ENABLE);

Hast du dir die Beispiele auf der ST Homepage angeschaut?

http://www.st.com/stonline/stappl/st/com/SOFTWARE_RESOURCES/SW_COMPONENT/FIRMWARE/stm32f2xx_stdperiph_lib.zip

Im Anhang das Bsp von ST auf der Lib.

von Denis S. (h44656e)


Lesenswert?

Hallo
Jetzt wird es richtig kriminell!
Es tickt! Aber unregelmäßig.

Gruß
Denis

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
Noch kein Account? Hier anmelden.