如题,在用STM32F091的TIM16作为输入捕获中断时,不进中断,请大神们指点。代码如下:
IO口配置:
RCC_AHBPeriphClockCmd( RCC_AHBPeriph_GPIOE, ENABLE);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0|GPIO_Pin_1;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP ;
GPIO_Init(GPIOE, &GPIO_InitStructure);
GPIO_SetBits(GPIOE,GPIO_Pin_0);
GPIO_SetBits(GPIOE,GPIO_Pin_1);
GPIO_PinAFConfig(GPIOE, GPIO_PinSource0, GPIO_AF_0);//TIM17_CH1
GPIO_PinAFConfig(GPIOE, GPIO_PinSource1, GPIO_AF_0);//TIM16_CH1
RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM16 , ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM17 , ENABLE);
TIM_TimeBaseStructure.TIM_Prescaler = 4800;
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
TIM_TimeBaseStructure.TIM_Period =10;
TIM_TimeBaseStructure.TIM_ClockDivision = 0;
TIM_TimeBaseStructure.TIM_RepetitionCounter = 0;
TIM_TimeBaseInit(TIM16, &TIM_TimeBaseStructure);
TIM_TimeBaseInit(TIM17, &TIM_TimeBaseStructure);
TIM_ICInitStructure.TIM_Channel=TIM_Channel_1;
TIM_ICInitStructure.TIM_ICPolarity=TIM_ICPolarity_Rising;
TIM_ICInitStructure.TIM_ICSelection=TIM_ICSelection_DirectTI;
TIM_ICInitStructure.TIM_ICPrescaler=TIM_ICPSC_DIV1;
TIM_ICInitStructure.TIM_ICFilter=0;
TIM_ICInit(TIM16,&TIM_ICInitStructure);
TIM_ICInit(TIM17,&TIM_ICInitStructure);
TIM_Cmd(TIM16, ENABLE);
TIM_Cmd(TIM17, ENABLE);
NVIC_InitStructure.NVIC_IRQChannel = TIM16_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPriority=0x02;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
TIM_ITConfig(TIM16,TIM_IT_CC1 ,ENABLE);
TIM_ITConfig(TIM17,TIM_IT_CC1 ,ENABLE);


楼主
|
回复于 2018-09-04
沙发
{
uint16_t temp=0;
if(TIM_GetITStatus(TIM16,TIM_IT_CC1)!=RESET)
{
WaterCNT++;
WaterIncrease++;
temp=TIM16->CNT;
if(temp>FlowLastCNT)
WaterSpeed= 600000/(temp-FlowLastCNT);
else
WaterSpeed= 600000/(temp+60000-FlowLastCNT);
FlowLastCNT=temp;
}
TIM_ClearITPendingBit(TIM16,TIM_IT_CC1);
}
-
- 0000000000000000
-
1888 发帖7917 回复34980 积分
- 私信他 +关注
回复于 2018-09-04
2#
这是072的仅供参考
/**
* @brief Configure the TIM IRQ Handler.* @param None
* @retval None
*/
static void TIM_Config(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
NVIC_InitTypeDef NVIC_InitStructure;
TIM_ICInitTypeDef TIM_ICInitStructure;
/* TIM2 clock enable */
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2, ENABLE);
/* GPIOB clock enable */
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOB, ENABLE);
/* TIM2 chennel2 configuration : PB.03 */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP ;
GPIO_Init(GPIOB, &GPIO_InitStructure);
/* Connect TIM pin to AF2 */
GPIO_PinAFConfig(GPIOB, GPIO_PinSource3, GPIO_AF_2);
/* Enable the TIM2 global Interrupt */
NVIC_InitStructure.NVIC_IRQChannel = TIM2_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
/* ---------------------------------------------------------------------------
TIM2 configuration: PWM Input mode
The external signal is connected to TIM2 CH2 pin (PB.03)
TIM2 CCR2 is used to compute the frequency value
TIM2 CCR1 is used to compute the duty cycle value
In this example TIM2 input clock (TIM2CLK) is set to APB1 clock (PCLK1), since
APB1 prescaler is set to 1.
TIM2CLK = PCLK1 = HCLK = SystemCoreClock
External Signal Frequency = SystemCoreClock / TIM2_CCR2 in Hz.
External Signal DutyCycle = (TIM2_CCR1*100)/(TIM2_CCR2) in %.
Note:
SystemCoreClock variable holds HCLK frequency and is defined in system_stm32f0xx.c file.
Each time the core clock (HCLK) changes, user had to call SystemCoreClockUpdate()
function to update SystemCoreClock variable value. Otherwise, any configuration
based on this variable will be incorrect.
--------------------------------------------------------------------------- */
TIM_ICInitStructure.TIM_Channel = TIM_Channel_2;
TIM_ICInitStructure.TIM_ICPolarity = TIM_ICPolarity_Rising;
TIM_ICInitStructure.TIM_ICSelection = TIM_ICSelection_DirectTI;
TIM_ICInitStructure.TIM_ICPrescaler = TIM_ICPSC_DIV1;
TIM_ICInitStructure.TIM_ICFilter = 0x0;
TIM_PWMIConfig(TIM2, &TIM_ICInitStructure);
/* Select the TIM2 Input Trigger: TI2FP2 */
TIM_SelectInputTrigger(TIM2, TIM_TS_TI2FP2);
/* Select the slave Mode: Reset Mode */
TIM_SelectSlaveMode(TIM2, TIM_SlaveMode_Reset);
TIM_SelectMasterSlaveMode(TIM2,TIM_MasterSlaveMode_Enable);
/* TIM enable counter */
TIM_Cmd(TIM2, ENABLE);
/* Enable the CC2 Interrupt Request */
TIM_ITConfig(TIM2, TIM_IT_CC2, ENABLE);
}
-
- xiaomiking
-
1147 发帖6357 回复18609 积分
- 私信他 +关注
块
导
航
举报
请选择举报类别
- 广告垃圾
- 违规内容
- 恶意灌水
- 重复发帖