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
also, my microcontroller is working with HSE - 72 mhz when I am trying it.
Your Low speed External oscillator is not oscillating.
Possibly a hardware problem. Soldering problem, capacitance problem.
Or
Have you initialised everything you need to.
Have a look at somebody elses RTC code, you may need to set a register or run some init code that does the same.
I'm guessing that
PWR_CR.DBP = 1; // Schreibschutz der BackupDomainRegister abschalten
is like
PWR_BackupAccessCmd( ENABLE ); /* Allow access to BKP Domain */
I have not used the exact processor but in the STM32F4 there is a special unlock sequence after PWR_CR.DBP = 1; because the micro is probably in back up domain reset state.
This is:
RTC_WPR = 0xCA; //unlock write protection
RTC_WPR = 0x53; //unlock write protection
Only after that can you change the clock source.
Check the RTC initialization and configuration section of your processor reference manual very carefully.
I hope this helps.
I have to ask one question, before I solve this problem.
I know that, if stm32 m3 microcontrollers run in overclock, they can be broken unit of osc.
I have broken one microprocessor like that. (HSE unit has broken) Therefore, I have to ask that, you can see my clock configuration bellow. Is it true? or Is there any overclock for any units?