2015-01-18 09:54 PM
Basically what my problem is Once I de-init the Timer after a successful operation I'm not able to re-init it again...
I am writing a program to generate a delay using timer whose delay canbe varied according to the user defined value. But for the First timeI'm able to generate the desired delay but Once I de-initialize I'm notable to reinitialize the timer again void TIM2_irq(void){ if (TIM_GetITStatus(TIM2, TIM_IT_Update) != RESET) { count++; TIM_ClearITPendingBit(TIM2, TIM_IT_Update); if(count == Max_Cnt ) { flag=1; //Once the defined count is reached set the flagTIM_DeInit(TIM2);
//Deinitialise the Timer } }}void delay_using_TIM(float delay_val){ Max_Cnt = delay_val *10; NVIC_InitTypeDef NVIC_InitStructure; TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure; /* Enable the TIM2 gloabal Interrupt */ NVIC_InitStructure.NVIC_IRQChannel = TIM2_IRQn; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0; NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure); /* TIM2 clock enable */ RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2, ENABLE); /* Time base configuration */ TIM_TimeBaseStructure.TIM_Period = 5; TIM_TimeBaseStructure.TIM_Prescaler = 0x410; // Verfied 100 microsec for timer expiry TIM_TimeBaseStructure.TIM_ClockDivision = 0; TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up; TIM_TimeBaseInit(TIM2, &TIM_TimeBaseStructure); /* TIM IT enable */ TIM_ITConfig(TIM2, TIM_IT_Update, ENABLE); /* TIM2 enable counter */ TIM_Cmd(TIM2, ENABLE); while(!flag); flag=0;}int main(){ while(1) { GPIO_SetBits(GPIOB, GPIO_Pin_6); //Gpio is already initialised delay_js(6.2); GPIO_ResetBits(GPIOB, GPIO_Pin_6); rtos_delay_milliseconds(10); }}Is this the proper way of de-initializing the Timer ?Please help #stm32f4 #discovery #stm32f2 #timers