cancel
Showing results for 
Search instead for 
Did you mean: 

what are the initial values to be fed in rtc_tr and rtc_dr registers?

prasad kadam
Associate
Posted on July 13, 2018 at 09:28

hello 

 I  am new to stm series microcontrollers and am developing driver for my projects. for the rtc driver am stuck at this point for so long that am not able to put right values in rtc time and date register, am not using cubeMX or any built in hal or hal library, the controller am using is the discovery board with stm32f051x8. am done with previous initializations of rtc. but not getting that what values should to kept in rtc_tr and rtc_dr registers as initial values. I need to use 12H format so if any one can tell me about some more details of how to put values in those regs. and how to read those values to see the accurate time and date. I think that an example will be helpful with values in BCD tens and BCD units format.

here is my code

#include'stm32f0xx.h'

#include'stm32f051x8.h'

void RTCInitialized()

{

 RCC->CSR |= RCC_CSR_LSION;

 RCC->APB1ENR |=RCC_APB1ENR_PWREN;

 RCC->BDCR = RCC_BDCR_RTCEN;

 PWR->CR |= 0X00000100;

 RTC->WPR = 0XCA;

 RTC->WPR = 0X53;

 RTC->ISR |= 0X00000080;  // entering INIT mode of rtc

 RTC->CR |= RTC_CR_FMT;

 RCC->BDCR |= 0X00000200;

 while((RTC->ISR & RTC_ISR_INITF) == 1)

 {

  RTC->ISR & RTC_ISR_INITF;

 }

 RTC->PRER = 0x007F0137; // given in trm code sample for lsi.    

  // these are the trials

for setting up time

/* RTC->TR = RTC_TR_PM | RTC_TR_HT_0 |RTC_TR_HU_0

    |RTC_TR_MNT_0  |RTC_TR_MNT_1

    |RTC_TR_ST |RTC_TR_SU;

 RTC->DR =  RTC_DR_YT_0 | RTC_DR_YU_3|RTC_DR_WDU_2

      |RTC_DR_MU_0|RTC_DR_MU_1|RTC_DR_MU_2

    |RTC_DR_DT_0| RTC_DR_DU_1; */

// RTC->TR = 10100100000001000000000;  

  // these are the trials

for setting up time

// RTC->TR =0X521812;                                 //0X00520800;  

  // these are the trials

for setting up time

 RTC->DR =0X182713;

 RCC->BDCR |= 0X00008200;

 RTC->ISR &= ~(RTC_ISR_INIT);

 RTC->WPR = 0XFE;

 RTC->WPR = 0X64;

}
2 REPLIES 2

>>am not using cubeMX or any built in hal or hal library

And wasting a lot of time, it is clearly a super good strategy for the new swimmer to jump in the deepest end of the pool.

You either need to understand the Reference Manual better than the people that coded the HAL, or you need to review the HAL code until you understand it, and then cherry pick, or just cut-n-paste the pieces you need.

There are very few people here up for wasting a lot of their time fighting other people's fights.

Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..

I'd say you have to 1. wait until LSI is up, i.e. after enabling it by setting RCC_CSR.LSION you have to wait until RCC_CSR.LSIRDY is set, and then select it as RTC clock in RCC_BDCR, *before* you proceed with any RTC register access.

Note that LSI is a very unprecise RC oscillator, not suitable at all to maintain real time.

JW