cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F3 Clock() function error (Fixed)

theo
Associate
Posted on June 19, 2014 at 17:09

Edit: I found a solution using the SysTick_Handler function, so never mind this post.

Hi everyone,

I'm currently programming an STM32F303VC using Keil uVision v5, and I'm trying to use the clock() function to set up a timing function. However, every time I store the clock() function's output I get the same number. Here's my code and the results.

&sharpinclude ''main.h''

&sharpinclude ''time.h''

/* Private variables ---------------------------------------------------------*/

  RCC_ClocksTypeDef RCC_Clocks;

__IO uint32_t TimingDelay = 0;

__IO uint32_t UserButtonPressed = 0;

clock_t timer;

clock_t timer2;

double timer_double;

double timer2_double;

__IO uint8_t DataReady = 0;

__IO uint8_t PrevXferComplete = 1;

__IO uint32_t USBConnectTimeOut = 100;

int main(void)

{  

// Configure USART pin

  RCC_GetClocksFreq(&RCC_Clocks);

SysTick_Config(RCC_Clocks.HCLK_Frequency / 100);

RCC_Configuration();

  GPIO_Configuration();

  USART1_Configuration();

//Timer Test code

timer=clock();

timer_double = (double)timer;

Delay(50); //Delay 500ms

timer2 = clock();

timer2_double=(double)timer2;

USARTWriteStr(''\r\nTimer 1 ticks: '');

USARTWriteFloat((double)timer); //Write this to USART pin

USARTWriteStr(''\r\n'');

USARTWriteStr(''Timer 2 ticks: '');

USARTWriteFloat((double)timer2);

USARTWriteStr(''\r\n'');

while(1)

{

  }     

}

Output:

Timer 1 ticks: 4294967296.000000

Timer 2 ticks: 4294967296.000000

The USART configuration functions were taken from this [DEAD LINK /public/STe2ecommunities/mcu/Lists/cortex_mx_stm32/Flat.aspx?RootFolder=/public/STe2ecommunities/mcu/Lists/cortex_mx_stm32/usart%20code&FolderCTID=0x01200200770978C69A1141439FE559EB459D7580009C4E14902C3CDE46A77F0FFD06506F5B&currentviews=648]example

And I based my clock() function use off of this 

http://www.tutorialspoint.com/c_standard_library/c_function_clock.htm

Am I doing something wrong, or is the UART configuration somehow affecting the clock functionality? Thanks for the help.

#stm32f3 #timers #clock()
1 REPLY 1
theo
Associate
Posted on June 19, 2014 at 17:40

Never mind, I found a solution using the SysTick_Handler function.