cancel
Showing results for 
Search instead for 
Did you mean: 

Difficulty in Setting Interrupts

Amir1
Associate II

Hello All

Could someone kindly help me figure out what may be wrong with this code (only the relevant part has been pasted here)?

The objective is to toggle the LED through interrupts coming from TIM7, the simplest timer I could setup. In despair, I have placed all the callback functions that I could find in the header file. The code compiles error free, and the initializations seem to take place with no issue. It just does not toggle the LED once it reaches the while(1) loop.

Thanks in advance

Amir

...

 ​__enable_irq();

HAL_NVIC_EnableIRQ(TIM7_IRQn);

HAL_TIM_Base_Start_IT(&htim7);

HAL_TIM_IRQHandler(&htim7);

HAL_GPIO_WritePin(LD2_GPIO_Port, LD2_Pin, GPIO_PIN_SET); // for test in stepped debugging mode

HAL_GPIO_TogglePin(LD2_GPIO_Port, LD2_Pin); // for test in stepped debugging mode

while (1)

{

}

}

void __HAL_TIM_OC_DelayElapsedCallback(TIM_HandleTypeDef *htim)

{

HAL_GPIO_TogglePin(LD2_GPIO_Port, LD2_Pin);

}

void __HAL_TIM_IC_CaptureCallback(TIM_HandleTypeDef *htim)

{

HAL_GPIO_TogglePin(LD2_GPIO_Port, LD2_Pin);

}

void __HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim)

{

HAL_GPIO_TogglePin(LD2_GPIO_Port, LD2_Pin);

}

void __HAL_TIM_PWM_PulseFinishedCallback(TIM_HandleTypeDef *htim)

{

HAL_GPIO_TogglePin(LD2_GPIO_Port, LD2_Pin);

}

void HAL_TIM_TriggerCallback(TIM_HandleTypeDef *htim)

{

HAL_GPIO_TogglePin(LD2_GPIO_Port, LD2_Pin);

}

void HAL_TIM_ErrorCallback(TIM_HandleTypeDef *htim)

{

HAL_GPIO_TogglePin(LD2_GPIO_Port, LD2_Pin);

}

void HAL_TIMEx_CommutationCallback(TIM_HandleTypeDef *htim)

{

HAL_GPIO_TogglePin(LD2_GPIO_Port, LD2_Pin);

}

void HAL_TIMEx_BreakCallback(TIM_HandleTypeDef *htim)

{

HAL_GPIO_TogglePin(LD2_GPIO_Port, LD2_Pin);

}

...

2 REPLIES 2

For IRQs to actually work you'd need an TIM7_IRQHandler() that calls HAL_TIM_IRQHandler(&htim7); when they occur, and it in turn will call your callbacks.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

​Thanks. It works now.

Do you happen to have a document that explains these subtleties?

Amir