Hello All,
I have a stm32f303 micro, and I am using Keil's uVision4. I am running at 8 Mhz. The function below is being called ok. But for some reason when I look at TIM7 CNT I don't have anything? Just 0x00, no up count?
void TimerInit ( void ) {
// 976 Hz 15625 Hz RCC->CFGR = 0x38F0; //(HCLK/16), (SYSCLK/512), (HSI Selected clock at SW) RCC->CR = 0x01; //HSI enabled RCC->APB2ENR = 0x01; //Enabling System Clock enabled RCC->APB1RSTR = 0x20; //Reseting TIM7 1=reset, 0=no-action RCC->APB1ENR = 0x20; //Enabling TIM7 Clock TIM7->CR1 = 0x85; //Clock enabled, URS enabled TIM7->SR = 0x00; //Clearing the UIF (Update Interrupt Flag) TIM7->DIER = 0x01; //Enabling the interrupt for the overflow of the Timer 7 TIM7->EGR = 0x01; //Event Generation Register to Update Registers TIM7->ARR = 0x8E; //The value required for the Event to occur, Counter value.
}
Does anyone have any ideas on what to check? Any suggestions?
I really appreciate the help, Jim
Passing numeric values to registers is a bad idea my friend, Why you don't use the standard peripheral library that comes with every STM32 microcontroller? For example this is an initialization function for TIM4 in a STM32F4xx
void TIM4_Config(void){ TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure; NVIC_InitTypeDef NVIC_InitStructure; /* Enable SYSCFG clock */ RCC_APB2PeriphClockCmd(RCC_APB2Periph_SYSCFG, ENABLE); /* Enable the TIM4 global Interrupt */ NVIC_InitStructure.NVIC_IRQChannel = TIM4_IRQn; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0; NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure); //Timer clock RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM4, ENABLE); /* Time base configuration */ // funcion que inicializa la estructura con sus valores por defento TIM_TimeBaseStructInit(&TIM_TimeBaseStructure); TIM_TimeBaseStructure.TIM_Period = 9999; // valor hasta el cual contara el timer TIM_TimeBaseStructure.TIM_Prescaler = 99; TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up; //Modo de conteo TIM_TimeBaseInit(TIM4, &TIM_TimeBaseStructure); /* TIM Interrupts enable */ TIM_ITConfig(TIM4, TIM_IT_Update, ENABLE); TIM_Cmd(TIM4, ENABLE); }
the code is perhaps longer but much more clean. Regards
Hello,
I am trying the STD Library but I don't have the right header files. What where the header files that you are using for the timer init?
Thankyou for the help, Jim
Well, I tried the code that you used for the TIM4 and I have it compiling now. When I run it and I look at the counter register I don't see any incrementing? Is that normal? Is there something that needs to be set in software?
I am using uVision4 by Keil.
Thankyou, Jim