STM32f103 and measuring of LSI frequency
Hello,
I'm trying to use LSI for RTC, but can't calculate correct prescaler value for RTC. And for each time I got different results(~+/-15sec. for each 2minutes), when test it. I found note in Reference manual (7.2.5 LSI clock Note) for STM32F103C8T6 that said: LSI measuring is only available for high-density, XL-density and connectivity line devices. Is exist some possibility to measuring of LSI frequency for STM32F103C8T6, for use this value to calculate RTC prescaler? Code for configure RTS with LIS:RCC->
APB1ENR
|= RCC_APB1ENR_BKPEN | RCC_APB1ENR_PWREN;
//Enable the APB1 backup domain and power
PWR->
CR
|= PWR_CR_DBP;
//Enable access to backup domain
RCC->
CSR
|= RCC_CSR_LSION;
//LSI 40k oscillator enabled
while
((RCC->
CSR
& RCC_CSR_LSIRDY) == 0);
//LSI ready
RCC->BDCR
|= RCC_BDCR_RTCSEL_LSI;
//Select LSE as the RTC clock source
RCC->
BDCR
|= RCC_BDCR_RTCEN;
//Enable the RTC clock
wait_sync();
//Poll the RSF bit in the RTC_CRL register until the RTC registers are synchronized
RTC->
CRL
&= ~RTC_CRL_RTOFF;
wait_ready
();
//Poll the RTOFF bit in the RTC_CRL register until the last operation on the RTC registers is over
/*
RTC->CRH |= RTC_CRH_SECIE;
NVIC->ISER[0] = NVIC_ISER_SETENA_3;
NVIC->IABR[0] |= NVIC_IABR_ACTIVE_3;
*/
RTC->
CRH
&= ~RTC_CRH_SECIE;
RTC->
CRH
&= ~RTC_CRH_OWIE;
RTC->
CRH
&= ~RTC_CRH_ALRIE;
RTC->
CRL
|= RTC_CRL_CNF;
//enter into RTC configuration mode
RTC->
PRLH
= 0;
RTC->
PRLL
= 40000-1;
//set iterations count for 1 second, LSI = 40k(39.967Hz)
RTC->
CNTH
= 0x0000;
//reset RTC value
RTC->
CNTL
= 0x0000;
//reset RTC value
RTC->
CRL
&= ~RTC_CRL_CNF;
//exit form RTC configuration mode
while
((RCC->
BDCR
& RCC_BDCR_RTCEN) != RCC_BDCR_RTCEN);
PWR->
CR
&= ~PWR_CR_DBP;
// disable access to RTC registers
#rcc_bdcr_rtcen #stm32f103c8t6 #dwt->cyccnt