Forum: Mikrocontroller und Digitale Elektronik [STM32] RealTimeClock


von Bernhard B. (schluchti)


Lesenswert?

Hi,

ich bin gerade dabei die RTC des STM32 zum Laufen zu bekommen. Die 
Existenz der Firmware-Library von ST ist mir bekannt, aber ich möchte es 
gerne selbst hinbekommen.

Meine Initialisierungsroutine sieht im Moment so aus:
1
void rtc_init(void)
2
{
3
 //access to backup register & RTC
4
 RCC->APB1ENR |= RCC_APB1ENR_PWREN; 
5
 RCC->APB1ENR |= RCC_APB1ENR_BKPEN; 
6
 PWR->CR |= PWR_CR_DBP;   //access to backup register
7
8
 RCC->BDCR |= RCC_BDCR_RTCEN; //enable RTC
9
 RCC->BDCR |= RCC_BDCR_RTCSEL_NOCLOCK; //LSE oscillator clock used as RTC clock
10
 RCC->BDCR |= RCC_BDCR_LSEON; //External Low Speed oscillator enable
11
12
 while((RCC->BDCR & RCC_BDCR_LSERDY) == 0) //external Low Speed oscillator Ready?
13
 {
14
 }
15
 
16
 
17
  while ((RTC->CRL & RTC_CRL_RTOFF)== 0)   //end of write operation?
18
  {
19
  }
20
  //enter configuration mode
21
 RTC->CRL |= RTC_CRL_CNF;
22
23
  RTC->PRLL = 0x7FFF;  //signal period of 1sec.
24
  RTC->DIVL = 0x7FFF; //set RTC Prescaler
25
  
26
  //reset 32bit counter
27
  RTC->CNTH = 0x0000;
28
  RTC->CNTL = 0x0000;
29
30
31
 RTC->CRL &= ~(RTC_CRL_CNF); //exit configuration mode
32
 while ((RTC->CRL & RTC_CRL_RTOFF)== 0)   //end of write operation?
33
 {
34
 }
35
36
}

Das Problem ist, dass RTOFF nach dem Ende des Schreibprozesses nicht 
mehr "1" wird (mit dem Debugger überprüft).

Eigentlich hab ich ja alles, wie im Manual beschrieben, gemacht:

Configuration procedure:
1. Poll RTOFF, wait until its value goes to ‘1’
2.  Set the CNF bit to enter configuration mode
3.  Write to one or more RTC registers
4.  Clear the CNF bit to exit configuration mode
5.  Poll RTOFF, wait until its value goes to ‘1’ to check the end of the 
write operation.

The write operation only executes when the CNF bit is cleared; it takes 
at least three RTCCLK cycles to complete.

Jemand ne Idee was ich übersehe?

von (prx) A. K. (prx)


Lesenswert?

Bernhard B. schrieb:

>  RCC->BDCR |= RCC_BDCR_RTCSEL_NOCLOCK; //LSE oscillator clock used as
> RTC clock

Das NOCLOCK kommt dir überhaupt nicht seltsam vor?

Denk dran, sowohl Controller wie Compiler sind "I do what you say not 
what you mean" Geräte, auch wenn man es, wie der Kommentar zeigt, gern 
andersrum hätte.

von (prx) A. K. (prx)


Lesenswert?

PS: DIVL ist r/o.

von Bernhard B. (schluchti)


Lesenswert?

Argh, hab die falsche Bitdefinition aus dem Headerfile kopiert...
Eigentlich hätts ja schon bei NOCLOCK klick machen sollen, da hast du 
Recht. Aber irgendwie ist mir das überhaupt nicht aufgefallen. Sowas ist 
echt ärgerlich..
Auf jeden Fall vielen Dank!

edit: Auch Danke für den Hinweis mit read only

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.