2014-06-19 08:09 AM
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.000000Timer 2 ticks: 4294967296.000000The 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¤tviews=648]exampleAnd I based my clock() function use off of thishttp://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()2014-06-19 08:40 AM
Never mind, I found a solution using the SysTick_Handler function.