| June 28, 2012 - 5:31pm Guest  | I'm working on Time6 Interrupt for STM32F103zet6. I intended to creat a 200ms timer interrupt and when the timer is up, display something.Please see my code below.     /* TIM6 Periph clock enable */RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM6, ENABLE);
   /*Timer6 configuration------------------------------------------------*/TIM_PrescalerConfig(TIM6, 223, TIM_PSCReloadMode_Update);//0.25Mhz=56M/224 0.125Mhz=56M/448
 TIM_SetAutoreload(TIM6, 50000);//50000=200ms timer
 TIM_Cmd(TIM6, ENABLE);  /* TIM6 enable counter */
   /* Enable TIM6 Update interrupt */TIM_ITConfig(TIM6, TIM_IT_Update, ENABLE);
   /* Enable the TIM6 Interrupt */NVIC_InitStructure.NVIC_IRQChannel = TIM6_IRQn;
 NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
 NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
 NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
 NVIC_Init(&NVIC_InitStructure);
 void TIM6_IRQHandler(void){
 TIM_ClearITPendingBit(TIM6, TIM_IT_Update);
 Timer200msFlag = !Timer200msFlag;
 if(Timer200msFlag == 1)
 {
 GPIO_WriteBit(GPIOF, GPIO_Pin_6, Bit_SET);
 }
 else
 {
 GPIO_WriteBit(GPIOF, GPIO_Pin_6, Bit_RESET);
 }
 }
 void main(void)
 {
 while(Timer200msFlag ==0);
 Display();
 }
 I can see LED(port F6) flashes @200ms speed and Timer200msFlag  toggles, but on the main function,Display() function is never excuted.
 Thanks for your help! | 
          
Hi,
It's hard to tell without the complete project, but I suggest you check that Timer200msFlag is declared as "volatile".
Otherwise the "while" in the main can be optimized as an "if".
I hope it helps.
Vincent