AnsweredAssumed Answered

RTC initialization faliure

Question asked by balazs.peter on Sep 12, 2016
Latest reply on Sep 12, 2016 by balazs.peter
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;
}

Outcomes