AnsweredAssumed Answered

why interrup occerd when TIM1 is not ENABLE??

Question asked by hossein hosseini on Jan 25, 2018
Latest reply on Jan 28, 2018 by hossein hosseini

hi guys.

i wrote a code with IAR , and when is run the code in stm32f103ret , cpu go to  the interrupt s routin.
i dont know why??!!
i want to have 1msecond delay for each timer priode , but i cant do that. when the code runs , cpu go to interrupt routine fanction. i do some thing that i know. but i cant do this activity. this is my code:

who know why I cant??
so thanks.

 

#include "stm32f10x.h"
#include "stm32f10x_gpio.h"  // for Enable LCD
#include "stm32f10x_rcc.h"   //for Enable LCD
#include "stm32f10x_tim.h"
#include "LCDLib.h"
#include "delay.h"


void tim_init(void);
void GPIO_init(void);


void TIM1_UP_TIM16_IRQHandler (void){
  int i;
  i = TIM_GetPrescaler(TIM1);
 
  lcdGoxy(1 , 2);
  lcdPutInt(i);
  lcdGoxy(1 , 3);
  lcdPutString ("tim activated");
  TIM_ClearITPendingBit(TIM1,TIM_IT_Update);

}

int main()
{  
  lcd_init();
  tim_init();
  GPIO_init();
  while(1){
    
  }
 
 
}

void tim_init(){     
 
  RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM1, ENABLE);
  TIM_TimeBaseInitTypeDef  TIM_TimeBaseStructure;
  /* Time base configuration */
  TIM_TimeBaseStructure.TIM_Period = 55000;
  TIM_TimeBaseStructure.TIM_Prescaler = 55999;
  TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1;
  TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;

  TIM_TimeBaseInit(TIM1, &TIM_TimeBaseStructure);
 
  TIM_ITConfig(TIM1, TIM_IT_Update, ENABLE); 
 
  NVIC_InitTypeDef NVIC_InitStructure;
  /* Enable the TIM2 global Interrupt */
  NVIC_InitStructure.NVIC_IRQChannel = TIM1_UP_IRQn;
  NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
  NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
  NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;

  NVIC_Init(&NVIC_InitStructure);
}

void GPIO_init(void){  
 
  RCC_APB2PeriphClockCmd  ( RCC_APB2Periph_GPIOA, ENABLE );  
 
  GPIO_InitTypeDef gpioA;     
  gpioA.GPIO_Mode = GPIO_Mode_Out_PP ;
  gpioA.GPIO_Pin = GPIO_Pin_0;
  gpioA.GPIO_Speed = GPIO_Speed_10MHz;  
  GPIO_Init  ( GPIOA,  &gpioA );
}

Outcomes