Author Topic: stm32f103vet6 LSE question  (Read 3149 times)

0 Members and 1 Guest are viewing this topic.

Offline KaramelTopic starter

  • Regular Contributor
  • *
  • Posts: 178
  • Country: tr
stm32f103vet6 LSE question
« on: August 29, 2015, 12:02:36 pm »
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.

Code: [Select]
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  ::)
 

Offline KaramelTopic starter

  • Regular Contributor
  • *
  • Posts: 178
  • Country: tr
Re: stm32f103vet6 LSE question
« Reply #1 on: August 29, 2015, 12:05:09 pm »
also, my microcontroller is working with HSE - 72 mhz when I am trying it.
 

Offline HackedFridgeMagnet

  • Super Contributor
  • ***
  • Posts: 2028
  • Country: au
Re: stm32f103vet6 LSE question
« Reply #2 on: August 29, 2015, 03:50:55 pm »
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
Quote
PWR_CR.DBP = 1;        // Schreibschutz der BackupDomainRegister abschalten
is like
Quote
PWR_BackupAccessCmd( ENABLE );  /* Allow access to BKP Domain */


« Last Edit: August 30, 2015, 09:35:22 am by HackedFridgeMagnet »
 

Offline plex

  • Newbie
  • Posts: 8
  • Country: gr
Re: stm32f103vet6 LSE question
« Reply #3 on: August 30, 2015, 09:06:32 am »
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.
 

Offline KaramelTopic starter

  • Regular Contributor
  • *
  • Posts: 178
  • Country: tr
Re: stm32f103vet6 LSE question
« Reply #4 on: August 30, 2015, 10:11:52 am »
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?

 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf