Hi everyone,
I am trying to active internal RTC unit of stm32f103vet6 via LSE. However, LSE osc is not able to open. I am using mikroc but It doesn't matter which platform we are using.
Why can't I work it? I am publishing my codes.
char a;
char ss2;
char ss1;
char dk2;
char dk1;
char sn2;
char sn1;
char text[30] = "00:00:00";
char tempstr[2];
unsigned long time;
void main() {
GPIO_Digital_Output(&GPIOB_BASE, _GPIO_PINMASK_8);
UART3_Init(9600); Delay_ms(100);
// Init power and clock for RTC
RCC_APB1ENR.BKPEN = 1; // Backup interface clock enable
RCC_APB1ENR.PWREN = 1; // Power interface clock enable
PWR_CR.DBP = 1; // Schreibschutz der BackupDomainRegister abschalten
RCC_BDCR.RTCSEL0 = 1; // 01: LSE oscillator clock used as RTC
RCC_BDCR.RTCSEL1 = 0; // 01: LSE oscillator clock used as RTC
RCC_BDCR.RTCEN = 1; // RTC clock enable
RCC_BDCR.LSEON = 1; // External 32 kHz oscillator ON
while(RCC_BDCR.LSERDY == 0); // microcontroller can not pass this code!
RCC_BDCR.BDRST = 1;
PWR_CR.DBP = 0; // Schreibschutz der BackupDomainRegister einschalten
// RTC-Register sycned?
RTC_CRL.RSF = 0;
while (RTC_CRL.RSF == 0);
// Config RTC
while (RTC_CRL.RTOFF == 0);
RTC_CRL.CNF = 1; // Configmode on
RTC_PRLL = 0x7FFF; // RTC-clock-prescaler
RTC_CRL.CNF = 0; // Configmode off
while (RTC_CRL.RTOFF == 0);
while(1)
{
// Burada RTC yi basacagiz
time = RTC_CNTL;
a = (time % 60);
sn2 = (a / 10) + 48;
sn1 = (a % 10) + 48;
a = ((time/60) % 60);
dk2 = (a / 10) + 48;
dk1 = (a % 10) + 48;
a = ((time/60/60) % 60);
ss2 = (a / 10) + 48;
ss1 = (a % 10) + 48;
UART3_Write(ss2); Delay_ms(10); UART3_Write(ss1); Delay_ms(10); UART3_Write(':'); Delay_ms(10);
UART3_Write(dk2); Delay_ms(10); UART3_Write(dk1); Delay_ms(10); UART3_Write(':'); Delay_ms(10);
UART3_Write(sn2); Delay_ms(10); UART3_Write(sn1); Delay_ms(10); UART3_Write(' '); Delay_ms(10); UART3_Write(' '); Delay_ms(10); UART3_Write(' ');
GPIOB_ODR.F8 = 1; Delay_ms(460); GPIOB_ODR.F8 = 0; Delay_ms(460);
}
}
as you can see, microcontroller can not pass this code
while(RCC_BDCR.LSERDY == 0); because, it never become ready. I am working with simple pcb. I can work with HSE and I have chaged 32.768khz crystall twice. I checked it. all connections are okay but why can not open it?
Best Regards,
Karamel