Posted on September 24, 2015 at 18:17I am new to timers. If anyone can see a fundamental mistake, please advise.
I have set up a time interrupt callback function which simply increments a integer.
It is based on a LED blinking example, so shouldn't saturate the processor?
Anyway, I have found that when I call the time and interrupt enable in my main function, not one single line after that point in my main function gets executed.
Is this normal?
int main(void)
{
SC_State SCState = SC_POWER_OFF;
RCC_Configuration();
NVIC_Configuration();
TIM3_Configuration();
TIM3_Enable();
flag++; // this never increments
// nothing that follows ever gets executed
.......
and the rest of my functions below.....
void RCC_Configuration(void)
{
/* --------------------------- System Clocks Configuration -----------------*/
/* TIM3 clock enable */
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3, ENABLE);
/* GPIOD clock enable */
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOD, ENABLE);
}
/**************************************************************************************/
/**************************************************************************************/
void NVIC_Configuration(void)
{
NVIC_InitTypeDef NVIC_InitStructure;
NVIC_InitStructure.NVIC_IRQChannel = TIM3_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
}
/**************************************************************************************/
void TIM3_IRQHandler(void)
{
if (TIM_GetITStatus(TIM3, TIM_IT_Update) != RESET)
{
testing++;
return; //also tried it without this return
}
}
/**************************************************************************************/
void TIM3_Configuration(void)
{
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
uint16_t Period, Prescaler;
Prescaler = 10000;
Period = ((SystemCoreClock / (2 * Prescaler)) / 4); // Period for 4 Hz frequency
/* Time base configuration */
TIM_TimeBaseStructure.TIM_Prescaler = Prescaler - 1;
TIM_TimeBaseStructure.TIM_Period = Period - 1;
TIM_TimeBaseStructure.TIM_ClockDivision = 0;
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
TIM_TimeBaseInit(TIM3, &TIM_TimeBaseStructure);
/* TIM3 enable counter */
}
void TIM3_Enable(void)
{
TIM_Cmd(TIM3, ENABLE);
TIM_ITConfig(TIM3, TIM_IT_Update, ENABLE);
}
void TIM3_Disable(void)
{
TIM_ITConfig(TIM3, TIM_IT_Update, DISABLE);
TIM_Cmd(TIM3, DISABLE);
}