Associate III
September 10, 2014
Question
External interrupt starting TIM2
- September 10, 2014
- 2 replies
- 750 views
Posted on September 10, 2014 at 16:33
Hello,
For a datalogging appIication (STM32F401 Discovery), TIM2 is used as an interrupt for ADC sampling rate .
/*----------------------------------------------------------------------------
Configuring TIM2 to trigger the ADC sampling rate
*----------------------------------------------------------------------------*/
void TIM2_Config(void)
{
TIM_TimeBaseInitTypeDef TIM2_TimeBase;
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2, ENABLE);
TIM_TimeBaseStructInit(&TIM2_TimeBase);
TIM2_TimeBase.TIM_Period = ((80000000 / 100000) - 1);
TIM2_TimeBase.TIM_Prescaler = 0:
TIM2_TimeBase.TIM_ClockDivision = 0;
TIM2_TimeBase.TIM_CounterMode = TIM_CounterMode_Up;
TIM_TimeBaseInit(TIM2, &TIM2_TimeBase);
TIM_SelectOutputTrigger(TIM2, TIM_TRGOSource_Update);
TIM_ITConfig(TIM2, TIM_IT_Update, ENABLE);
TIM_Cmd(TIM2, ENABLE);
}
/*----------------------------------------------------------------------------
Configuring Global interupt based on TIM2
*----------------------------------------------------------------------------*/
void NVIC_Config(void)
{
NVIC_InitTypeDef NVIC_InitStructure;
NVIC_InitStructure.NVIC_IRQChannel = TIM2_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
}
Next step is to enable TIM2 based on a external interrupt generated by the rising edge of GPIO PE What's the best way to create such an interrupt configuration? Any examples?
#interrupt #timer