PA8复用功能是TIM1的CH1,板子上PA8接LED,输出低电平LED亮,我配置好后,LED没有亮,是不是没设置好。
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA,ENABLE); //外设要开复用时钟?
RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM1,ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO,ENABLE);
GPIO_InitTypeDef GPIO_InitStructure;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8; //TIM1的CH1是PA8的复用功能
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; //复用输出
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_10MHz;
GPIO_Init(GPIOA,&GPIO_InitStructure);
使用了GPIOA的PIN8的复用功能,即TIM1_CH1,
TIM_OCInitTypeDef TIM_OCInitStructure;
TIM_OCInitStructure.TIM_OCMode =TIM_OCMode_Toggle;
TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
TIM_OCInitStructure.TIM_OutputNState = TIM_OutputNState_Enable;
TIM_OCInitStructure.TIM_Pulse = 20000;
TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_Low;
TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_Low;
TIM_OCInitStructure.TIM_OCIdleState = TIM_OCIdleState_Reset;
TIM_OCInitStructure.TIM_OCNIdleState = TIM_OCNIdleState_Set;
TIM_OC1Init(TIM1,&TIM_OCInitStructure);
TIM_ITConfig(TIM1,TIM_IT_CC1,ENABLE);
TIM_ClearITPendingBit(TIM1,TIM_IT_CC1); //使能输出比较中断
TIM_Cmd(TIM1,ENABLE);
TIM_CtrlPWMOutputs(TIM1,ENABLE);
只要TIM1_CH1输出低电平,LED应该亮,这样理解行不行? |