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?