HAL Timer interrupt
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2015-07-30 10:24 AM
Hello,
I tried to use the Timer interrupt. In the examples of the STM Discovery they used the HAL_TIM_PeriodElapsedCallback handle function. But with this does'nt work (The don't used HAL_NVIC_EnableIRQ(TIM2_IRQn), why?). Then I enabled the IRQ with HAL_NVIC_EnableIRQ(TIM2_IRQn). Now it calls everytime the Default Handler even if I implented the TIM2_IRQHandler function. What is the error I make?
//TIM2: APB1
// Timer channel 2 as base timer
void
timer2Init()
{
/* Variables */
TIM_HandleTypeDef initTimBase;
/* enable Clocks */
__HAL_RCC_TIM2_CLK_ENABLE();
// every 1ms an overflow
initTimBase.Instance = TIM2;
initTimBase.Init.CounterMode = TIM_COUNTERMODE_UP;
initTimBase.Init.Period = 32;
initTimBase.Init.Prescaler = 1344;
initTimBase.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
initTimBase.Init.RepetitionCounter = 0;
//HAL_TIM_Base_Start(&initTimBase);
//__HAL_TIM_CLEAR_IT(&initTimBase, TIM_IT_UPDATE);
HAL_TIM_Base_Init(&initTimBase);
HAL_TIM_Base_Start_IT(&initTimBase);
HAL_NVIC_SetPriority(TIM2_IRQn, 0, 0);
HAL_NVIC_EnableIRQ(TIM2_IRQn);
}
void
TIM2_IRQHandler(
void
)
{
int
i = 0;
i++;
//HAL_TIM_IRQHandler(&initTimBase);
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2015-07-30 10:28 AM
What is the error I make?
Are you doing this in a .CPP file?What part specifically are you using?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
‎2015-07-30 11:58 AM
I use a normal .c file.
I have a stm32f411re nucleo board.- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2015-07-30 12:27 PM
This is my new Code, but it calls everytime the Default Handler and not my TIM2_IRQHandler.
TIM_HandleTypeDef initTimBase;
//TIM2: APB1
// Timer channel 2 as base timer
void
timer2Init()
{
/* Variables */
/* enable Clocks */
__HAL_RCC_TIM2_CLK_ENABLE();
// every 1ms an overflow
initTimBase.Instance = TIM2;
initTimBase.Init.CounterMode = TIM_COUNTERMODE_UP;
initTimBase.Init.Period = 32;
initTimBase.Init.Prescaler = 1344;
initTimBase.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
initTimBase.Init.RepetitionCounter = 0;
HAL_TIM_Base_Init(&initTimBase);
//MspInit haben keinen Rückgabewert
HAL_TIM_Base_Start_IT(&initTimBase);
HAL_NVIC_SetPriority(TIM2_IRQn, 4, 1);
HAL_NVIC_EnableIRQ(TIM2_IRQn);
}
void
TIM2_IRQHandler(
void
)
{
HAL_TIM_IRQHandler(&initTimBase);
}
// just defined interrupt function
/**
* @brief Period elapsed callback in non blockfaceing mode
* @param htim : TIM handle
* @retval None
*/
void
HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim)
{
static
uint32_t
time
= 0;
time
++;
// 1sek
if
(!(
time
% 1000))
{
if
(htim->Instance == TIM2)
{
HAL_GPIO_TogglePin(GPIOA, GPIO_PIN_5);
}
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2015-07-30 12:48 PM
Setup the NVIC *before* calling HAL_TIM_Base_Start_IT(), because it's going to fire immediately
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
‎2015-07-31 11:48 AM
I tried that too but no changes.
#include <stdio.h>
#include ''diag/Trace.h''
#include ''stm32f411xe.h''
#include ''stm32f4xx_hal.h''
void
timer2Init();
// ----- main() ---------------------------------------------------------------
// Sample pragmas to cope with warnings. Please note the related line at
// the end of this function, used to pop the compiler diagnostics status.
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored ''-Wunused-parameter''
#pragma GCC diagnostic ignored ''-Wmissing-declarations''
#pragma GCC diagnostic ignored ''-Wreturn-type''
TIM_HandleTypeDef initTimBase;
int
main(
int
argc,
char
* argv[])
{
/* Variables */
uint32_t i;
HAL_Init();
gpioInit();
timer2Init();
// Button: PC13
// LED: PA5
// Infinite loop
while
(1)
{
for
(i = 0; i<500000; i++){}
HAL_GPIO_TogglePin(GPIOA, GPIO_PIN_5);
}
}
//TIM2: APB1
// Timer channel 2 as base timer
void
timer2Init()
{
/* enable Clocks */
__HAL_RCC_TIM2_CLK_ENABLE();
// every 1ms an overflow
initTimBase.Instance = TIM2;
initTimBase.Init.CounterMode = TIM_COUNTERMODE_UP;
initTimBase.Init.Period = 32;
initTimBase.Init.Prescaler = 1344;
initTimBase.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
initTimBase.Init.RepetitionCounter = 0;
HAL_TIM_Base_Init(&initTimBase);
//MspInit haben keinen Rückgabewert
HAL_TIM_Base_Start_IT(&initTimBase);
HAL_NVIC_SetPriority(TIM2_IRQn, 4, 1);
HAL_NVIC_EnableIRQ(TIM2_IRQn);
}
void
TIM2_IRQHandler(
void
)
{
HAL_TIM_IRQHandler(&initTimBase);
}
// just defined interrupt function
/**
* @brief Period elapsed callback in non blockfaceing mode
* @param htim : TIM handle
* @retval None
*/
void
HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim)
{
static
uint32_t
time
= 0;
time
++;
// 1sek
if
(!(
time
% 1000))
{
if
(htim->Instance == TIM2)
{
HAL_GPIO_TogglePin(GPIOA, GPIO_PIN_5);
}
}
}
#pragma GCC diagnostic pop
// ----------------------------------------------------------------------------
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2015-07-31 12:02 PM
Pasted code doesn't appear to reflect that, or the cause of it being multiply defined all of a sudden.
Ok, so remove one of the definitions. The auto-generation probably built the one in the stm32f4xx_it.c, review it, decide if it's doing materially what you're current one is doing, or not, and delete one of them.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
‎2015-08-01 12:58 PM
In my project folder in eclipse does not exist a file named stm32f4xx_it.c.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2015-08-01 7:17 PM
The error you posted earlier
./src/stm32f4xx_it.o:/home/martin/workspace/STM32_New/Debug/../src/stm32f4xx_it.c:12: first defined here
Has the file in/home/martin/workspace/STM32_New/src/stm32f4xx_it.cThe HAL/Cube stuff is outside of what I'm dealing with, the linker should provide some insight via the .MAP file, and you can examine the vector table, and perhaps a listing or disassembly of the created code.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
‎2015-08-02 12:28 PM
I created this file to test if it works. But it didn't. In my project there is any stm324fxx_it.c file
