cancel
Showing results for 
Search instead for 
Did you mean: 

RTC initialization faliure

balazspeter93
Associate
Posted on September 12, 2016 at 13:27

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;

}
2 REPLIES 2
stm32forum
Associate II
Posted on September 12, 2016 at 13:53

You need to read back trough the shadow register or set BYPSHAD (bypass shadow register) bit in the RTC_CR register.

balazspeter93
Associate
Posted on September 12, 2016 at 21:27

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?