cancel
Showing results for 
Search instead for 
Did you mean: 

how can i earn Real 1 second delay?!!

hossein hosseini
Associate II
Posted on October 20, 2017 at 14:28

hi,

i wrote Led blink with stm32f103re , and i did write this code :

&sharpinclude 'stm32f10x.h'

&sharpinclude 'delay.h'

int main()

{   

 

   RCC_DeInit  ( )  ;

   RCC_HSEConfig  ( RCC_HSE_ON) ;

   RCC_WaitForHSEStartUp  ( );  

   RCC_PLLConfig  ( RCC_PLLSource_HSE_Div1, 9) ;

   RCC_PLLCmd  ( ENABLE );  

   delay_ms(1);

   RCC_SYSCLKConfig  ( RCC_SYSCLKSource_PLLCLK );  

   RCC_HCLKConfig  ( RCC_SYSCLK_Div1 );

   RCC_PCLK2Config  ( RCC_HCLK_Div1 ); 

  RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA , ENABLE);  

 

  GPIO_InitTypeDef gpio;

  gpio.GPIO_Pin = GPIO_Pin_0;

  gpio.GPIO_Speed = GPIO_Speed_50MHz;

  gpio.GPIO_Mode = GPIO_Mode_Out_PP;

  GPIO_Init(GPIOA , &gpio); 

 

  while(1)   

  {

    GPIOA->BSRR = GPIO_Pin_0;

    delay_ms(300);   

    GPIOA->BSRR = (GPIO_Pin_0<<16);

    delay_ms(300);

  }

}

But when cpu do delay _ms(300) , the delay is not real , it wait for 3 seconds,

and i modify RCC_ ... register to earn 1 second  , but i cant earn that !!

what shall i do to earn real 1 second?

I test some ways , but i cant do that yet.

I know that i have problem in RCC setting , but i dont know where!!!

so thanks.

#1seconds
1 REPLY 1
Posted on October 20, 2017 at 15:02

The internal clocks can be output via PA8 (MCO)

Use SysTick to count 1000 milliseconds, or a TIM to count 36 million microseconds.

Better yet, get the TIM to toggle the pin.

Look at example code in system_stm32f1xx.c for how to set up and wait for HSE, PLL, etc.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..