2016-09-12 04:27 AM
Hi,
I'm having a problem trying to initialize the RTC in an STM32L051K8T6 It's like I don't have access to the RTC registers. After writing 0xCA in WPR register I read it back and I get zero. I did everything according to the reference manual and what I found how other people implemented it. Do you have any idea what might go wrong? int main() { RCC->APB2ENR |= RCC_APB2_USART1; RCC->IOPENR |= RCC_IOP_GPIOA; USARTConfig(); RCC->APB1ENR |= RCC_APB1_PWR; // Enable PWR clock PWR->CR |= PWR_CR_DBP; // Allow access to BKP Domain // Enable LSI RCC->CSR |= RCC_CSR_LSION; while(!(RCC->CSR & RCC_CSR_LSIRDY)); RCC->CSR |= RCC_CSR_RTCSEL; // Select RTC clock source RCC->CSR |= RCC_CSR_RTCEN; // Enable RTC RTC->WPR = 0xCA; USARTSendHex(RTC->WPR); // I get 0x00 here RTC->WPR = 0x53; // Enter initialization mode RTC->ISR |= RTC_ISR_INIT; while(!(RTC->ISR & RTC_ISR_INITF)); // never gets here... while(1) {} return 0; }2016-09-12 04:53 AM
You need to read back trough the shadow register or set BYPSHAD (bypass shadow register) bit in the RTC_CR register.
2016-09-12 12:27 PM
I found that I can not read WPR register cos it's always going to be zero according to the manual, however I don't fully understand what you're suggesting.
I can however read ISR register which has a value of 0x27 before and after trying to set the INIT flag. (I can't write it for some reason...)Any idea how this can happen?