Callback on Timer Triggered
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2023-08-03 04:36 AM
Hi,
I've got a timer in One Pulse Mode, triggered by a pulse on a GPIO pin.
Can I set it up to also get a callback in my application code when I receive that pulse? (i.e. when the timer starts)
Is this even possible or do I need to wire the signal to another GPIO pin as well?
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2023-08-03 04:53 AM
What chip?
You can generally have EXTI enabled on a pin that is still acting as a timer. Setting up an EXTI trigger for a rising edge on that pin would give you what you want.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2023-08-03 04:55 AM
Thanks for replying.
it's a STM32F303CBT6.
Is it possible to set this up through STM32CubeMX or do I need to write to the registers directly?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2023-08-03 05:04 AM
If you right-click a pin in CubeMX and select "Pin Stacking" you can then assign both functions (TIM and EXTI) to the pin. In theory this should work, but I did not test it.
Please mark one of my replies as the solution if you find that it answered the question, it helps close it out and lets others find it more easily.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2023-08-03 05:23 AM
Doesn't quite work. I can set the trigger in the timer's Mode panel, but when I do that the interrupt function has "no mode" and it doesn't seem to generate the code for the interrupt callback to work. If select the EXTI function again to fix that, the trigger is unset from the timer.
Alternatively I have found that I can call HAL_GPIO_Init twice: first to set the pin as an interrupt, then again to set it to the alternate function for the timer. That works, presumably because it's setting different registers each time; it feels hacky though because I guess a future HAL revision could "fix" this function to make sure all registers are set to a specific value every time, rather being than ignored.