最近用到STM32F100的定时器17,初始化如下,但是单步执行时却发现布恩给你改变寄存器的数据?不知道是什么原因啊?大家帮忙分析下
void Timer17_Configuration(void)
{
TIM_TimeBaseInitTypeDef TIM17_TimeBaseStructure;
TIM_ICInitTypeDef TIM_ICInitStruct;
NVIC_InitTypeDef NVIC_InitStructure;
GPIO_InitTypeDef GPIO_InitStructure;
// Enable TIM17 as CounterMode_Up
// Timer configuration in Clear on capture mode
RCC_APB1PeriphClockCmd(RCC_APB2Periph_TIM17, ENABLE);
TIM_DeInit(TIM17);
GPIO_StructInit(&GPIO_InitStructure);
/* Configure PB.07 as IR input */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7 ;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_Init(GPIOB, &GPIO_InitStructure);
TIM_TimeBaseStructInit(&TIM17_TimeBaseStructure);
/* Time Base configuration */
TIM17_TimeBaseStructure.TIM_Prescaler = 0xffff;
TIM17_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
TIM17_TimeBaseStructure.TIM_Period = U16_MAX;
TIM17_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV4;
TIM_TimeBaseInit(TIM17, &TIM17_TimeBaseStructure);
TIM_ICStructInit(&TIM_ICInitStruct);
TIM_ICInitStruct.TIM_Channel = TIM_Channel_1;
TIM_ICInitStruct.TIM_ICSelection = TIM_ICPolarity_Rising; //TIM_ICPolarity_Falling;
TIM_ICInitStruct.TIM_ICFilter = 0x0b;
TIM_ICInit(TIM17,&TIM_ICInitStruct);
// Enable the IR_TIMER IRQChannel
NVIC_InitStructure.NVIC_IRQChannel = TIM1_TRG_COM_TIM17_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = TIMx_PRE_EMPTION_PRIORITY;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = TIMx_SUB_PRIORITY;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
// Clear the TIMx's pending flags
TIM_ClearFlag(TIM17, TIM_FLAG_Update | TIM_FLAG_CC1 );
// Selected input capture and Update (overflow) events generate interrupt
TIM_ITConfig(TIM17, TIM_IT_CC1, ENABLE);
TIM_ITConfig(TIM17, TIM_IT_Update, ENABLE);
TIM_SetCounter(TIM17, 0);
TIM_Cmd(TIM17, ENABLE);
} |