TIMER STM32F429-DISCO
Hi,
i use the timer 10 to toggle a GPIO with a board STM32F429-DISCO.
int
init_timer
(
void
)
{
TIM_TimeBaseInitTypeDef
TIM_TimeBaseStructure;
NVIC_InitTypeDef
NVIC_InitStructure;
RCC_APB2PeriphClockCmd (
RCC_APB2Periph_TIM10
,
ENABLE
);
NVIC_InitStructure.NVIC_IRQChannel
=
TIM1_UP_TIM10_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority
=
0
;
NVIC_InitStructure.NVIC_IRQChannelSubPriority
=
1
;
NVIC_InitStructure.NVIC_IRQChannelCmd
=
ENABLE
;
NVIC_Init
(
&NVIC_InitStructure
);
// systemclock 180M BOARD STM32F429-DISCO
TIM_TimeBaseStructure.TIM_CounterMode
=
TIM_CounterMode_Up;
TIM_TimeBaseStructure.TIM_Prescaler
=
36000;
TIM_TimeBaseStructure.TIM_Period = 100;
TIM_TimeBaseInit
(
TIM10
,
&TIM_TimeBaseStructure);
TIM_Cmd
(
TIM10
,
ENABLE
);
TIM_ITConfig
(
TIM10
,
TIM_IT_Update
,
ENABLE
);
return
true
;
}
void
TIM1_UP_TIM10_IRQHandler
(
void
)
{
if
(
TIM_GetITStatus
(
TIM10
,
TIM_IT_Update
)
!=
RESET
)
{
TIM_ClearITPendingBit
(
TIM10
,
TIM_IT_Update
);
GPIO_ToggleBits(
GPIOG
,
GPIO_Pin_14); //toggle every 20 msec
}
}
I would like to modify the init_timer() function in order to generate an interrupt every 100 expernal pulse in the pin PA6 with the TIM10.
I have modified the function init_timer in this way
int
init_timer_new
(
void
)
{
TIM_TimeBaseInitTypeDef
TIM_TimeBaseStructure;
NVIC_InitTypeDef
NVIC_InitStructure;
NVIC_InitStructure.NVIC_IRQChannel
=
TIM1_UP_TIM10_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority
=
0
;
NVIC_InitStructure.NVIC_IRQChannelSubPriority
=
1
;
NVIC_InitStructure.NVIC_IRQChannelCmd
=
ENABLE
;
NVIC_Init
(
&NVIC_InitStructure
);
RCC_APB2PeriphClockCmd (
RCC_APB2Periph_TIM10
,
ENABLE
);
// systemclock 180M BOARD STM32F429-DISCO
TIM_TimeBaseStructure.TIM_CounterMode
=
TIM_CounterMode_Up;
TIM_TimeBaseStructure.TIM_Prescaler
=
0
;
TIM_TimeBaseStructure.TIM_Period
=
100
;
TIM_TimeBaseInit
(
TIM10
,
&TIM_TimeBaseStructure);
/* Connect TIM10 - pins to AF */
/* GPIOA clock enable */
RCC_AHB1PeriphClockCmd
(
RCC_AHB1Periph_GPIOA,
ENABLE
);
/* GPIOA Configuration: TIM10 CH1 (PA6) */
GPIO_InitTypeDef
GPIO_InitStructure;
GPIO_InitStructure.GPIO_Pin
=
GPIO_Pin_6
;
GPIO_InitStructure.GPIO_Mode
=
GPIO_Mode_AF;
// Input/Output controlled by peripheral
GPIO_InitStructure.GPIO_Speed
=
GPIO_Speed_100MHz;
GPIO_InitStructure.GPIO_OType
=
GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd
=
GPIO_PuPd_UP;
// Button to ground expectation
GPIO_Init
(
GPIOA
,
&GPIO_InitStructure
);
GPIO_PinAFConfig
(
GPIOA
,
GPIO_PinSource6
,
GPIO_AF_TIM10
);
TIM_TIxExternalClockConfig
(
TIM10
,
TIM_TIxExternalCLK1Source_TI1
,
TIM_ICPolarity_Rising
,
0
);
TIM_Cmd
(
TIM10
,
ENABLE
);
TIM_ITConfig
(
TIM10
,
TIM_IT_Update
,
ENABLE
);
return
true
;
}
However, with this change it doesn�t work!!!
Is there any flaw in my code?
#timer #interrupt #stm32f429