Difficulty in Setting Interrupts
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2019-03-10 2:59 PM
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);
}
...
- Labels:
-
Interrupt
-
STM32Cube MCU Packages
-
TIM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2019-03-10 6:14 PM
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.
Up vote any posts that you find helpful, it shows what's working..
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2019-03-11 7:28 AM
​Thanks. It works now.
Do you happen to have a document that explains these subtleties?
Amir
