0

I am trying to use timer interrupts to assign outputs directly to one specific foot of the chip using stm32f103c8t6 bluepill. What I want to achieve is to toggle the LED (connected to PC13) on and off by interrupt functions. But the result turns out to be that the PC13 LED is always on which means the interrupt function not working. I've tried debugging by using the st-link debugger, but when I run gdb on it, it would always go into hardware breakpoint which totally made me lost. I've configured TIM2 as in the screenshot of cube IDE and also with the clock configuration. My main function and the interrupt callback function are the follows, can someone please help me work out why the interrupt is not working?timer2 settings screenshot clock config screenshot

void SystemClock_Config(void);
static void MX_GPIO_Init(void);
static void MX_TIM2_Init(void);


int main(void)
{

uint16_t timer_val;
  
  HAL_Init();

  
  SystemClock_Config();

  
  MX_GPIO_Init();
  MX_TIM2_Init();
  HAL_TIM_Base_Start_IT(&htim2);



  while (1) {}
}

void HAL_TIM_Period_Elapsed_Callback(TIM_HandleTypeDef* which_TIM) {

    if (which_TIM == &htim2)
        HAL_GPIO_TogglePin(only_LED_GPIO_Port, only_LED_Pin);
}


  • "it would always go into hardware breakpoint which totally made me lost." Do you mean every time you do a Go you get back to the interrupt handler ? it is completely normal, while your CPU is halted , the timer keeps running so it fnishes counting again during the halt. You can setup the timer to be paused during debug (check the reference manual, registers DBGMCU APB1LFZ1). – Guillaume Petitjean Jan 06 '22 at 14:02
  • 1
    "he PC13 LED is always on" if the timer period is too small you always toggling the LED, it may give the impression to be ON all the time (but in fact it just blinks too fast) – Guillaume Petitjean Jan 06 '22 at 14:03
  • Your code doesn't configure the NVIC. Is it possible that you forgot to do so? – eeucalyptus Jan 13 '22 at 11:28

0 Answers0