AnsweredAssumed Answered

Problem with system clock

Question asked by mircea.dragu on Jun 30, 2014
Latest reply on Jun 30, 2014 by Clive One
Hi.

I use a STM32F103ZE microcontroller.
I try to change the System Clock (default is HSI) to HSE.
On my board is a HSE - cristal oscilator which value is 8 Mhz and i want to change it to 72 Mhz and it works.
But if i want to change it to a small value , for instance 24 Mhz i cannot change it, even if i made the setup (RCC->CFGR     |= (1 << 16) | (1 << 18); ).

One more quetion : how many clock cycles takes to execute an instruction ?

#include<stm32f10x.h>

void wait(void)  
{
     int  d;
     for(d = 0; d < 1000000; d++); 
}

int main (void) 
{     
     unsigned int i;
     RCC->CR &= ~(1 << 0);
     RCC->CR |= (1 << 19);
     RCC->CR &= ~(1 << 16);
     RCC->CR &= ~(1 << 24);
     RCC->CFGR &= ~(1 << 17);
     RCC->CFGR |= (1 << 0);
     RCC->CFGR &= ~(1 << 1);
        RCC->CFGR     |= (1 << 16) | (1 << 18) | (1 << 19) | (1 << 20);
     RCC->CFGR     |= (1 << 25) | (1 << 26);
     RCC->CR |= (1 << 24);
     RCC->CR |= (1 << 16);               
     
       RCC->APB2ENR |= (1UL << 7);              // Enable GPIOF

      GPIOF->CRL    =  0x33000000;       // PF.6, PF.7 defined as Outputs   
      GPIOF->CRH    =  0x33;                     // PF.8, PF.9 defined as Outputs

       while (1)  
       {                                                        
          for(i = 1<<6; i < 1<<10; i <<= 1) 
            {                                        
               GPIOF->BSRR = i;                 // Turn LED on
               wait();                
               GPIOF->BRR = i;                  // Turn LED of
          }
       }
}

Outcomes