Por causa da escassez de componentes no mercado, estou tendo dificuldade de comprar o componente que utilizo como RTC externo.
Assim estou querendo verificar a precisão do RTC interno do microcontrolador STM32F030R8T6, mas não consigo configurar os registradores para utilizar o LSE como clock do RTC, parece que os registradores estão protegidos mesmo após ser escrita a sequencia de desbloqueio "RTC_WPR = 0xCA; RTC_WPR = 0x53;"
Alguém teria alguma sugestão ou consideração para o código de config/inicialização abaixo?
- Código: Selecionar todos
void initInternalRTC(void){
/* (1) Write access for RTC registers */
/* (2) Enable init phase */
/* (3) Wait until it is allow to modify RTC register values */
/* (4) set prescaler, 40kHz/128 => 312 Hz, 312Hz/312 => 1Hz */
/* (5) New time in TR */
/* (6) Disable init phase */
/* (7) Disable write access for RTC registers */
RCC_APB1ENR.PWREN = 1; //Power interface clock enabled
PWR_CR.DBP = 1; //Disable RTC domain write protection, 1: Access to RTC enabled
RTC_WPR = 0xCA; /* (1) */
RTC_WPR = 0x53; /* (1) */
RCC_BDCR.BDRST = 1; //RTC domain software reset //1: Resets the entire RTC domain
RCC_BDCR.RTCSEL0 = 1; //Bits 9:8 RTCSEL[1:0]: RTC clock source selection
RCC_BDCR.RTCSEL1 = 0; //01: LSE oscillator clock used as RTC clock
RCC_BDCR.RTCEN = 1; //RTC clock enable
RCC_BDCR.LSEON = 1;
while(RCC_BDCR.LSERDY == 0){}//LSE oscillator ready
//RTC_ISR |= RTC_ISR.INIT; /* (2) */
RTC_ISR.INIT = 1;
while ((RTC_ISR & RTC_ISR.INITF) != RTC_ISR.INITF) /* (3) */
//while (RTC_ISR.INITF == 0) /* (3) */
{
/* add time out here for a robust application */
}
RTC_PRER = 0x007F0137; //0x007F00FF; /* (4) */
RTC_TR = 0b00000000000100100011000000000000;//RTC_TR.B22 | Time; /* (5) */
//RTC_ISR.INIT &=~ RTC_ISR.INIT; /* (6) */
RTC_ISR.INIT = 0;
RTC_WPR = 0xFE; /* (7) */
RTC_WPR = 0x64; /* (7) */
}
Segue também a tela de configuração do microcontrolador no MikroC.
