关于外部时钟模式

2019-07-20 12:46发布

        TIM_TimeBaseInitTypeDef TIM_TimeBaseInitStruct;
        NVIC_InitTypeDef NVIC_InitStruct;
        GPIO_InitTypeDef GPIO_InitStruct;

        RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM5|RCC_APB1Periph_TIM3,ENABLE);
        RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA,ENABLE);

        GPIO_InitStruct.GPIO_Mode=GPIO_Mode_IN;
        GPIO_InitStruct.GPIO_Pin=GPIO_Pin_0;
        GPIO_InitStruct.GPIO_PuPd=GPIO_PuPd_DOWN;
        GPIO_Init(GPIOA,&GPIO_InitStruct);
       
        GPIO_PinAFConfig(GPIOA,GPIO_PinSource0,GPIO_AF_TIM5);

        TIM_TimeBaseInitStruct.TIM_ClockDivision=0;
        TIM_TimeBaseInitStruct.TIM_CounterMode=TIM_CounterMode_Up;
        TIM_TimeBaseInitStruct.TIM_Period=arr;
        TIM_TimeBaseInitStruct.TIM_Prescaler=psc;//1s
        TIM_TimeBaseInit(TIM5,&TIM_TimeBaseInitStruct);
       
        TIM5->CCMR1&=~3;
        TIM5->CCMR1|=1<<0;        //CC1S=01         &#209;&#161;&#212;&#241;ê&#228;è&#235;&#182;&#203; IC1ó3é&#228;μ&#189;TI1é&#207;
        TIM5->CCMR1&=~(0XF<<4);         //IC1F=0000 &#197;&#228;&#214;&#195;ê&#228;è&#235;&#194;&#203;2¨&#198;÷ 2&#187;&#194;&#203;2¨

        TIM5->CCER&=~(1<<1);         //CC1P=0        é&#207;éy&#209;&#216;&#188;&#198;êy
        TIM5->SMCR|=5<<4;           //′¥·¢&#209;&#161;&#212;&#241;:&#194;&#203;2¨oóμ&#196;&#182;¨ê±&#198;÷ê&#228;è&#235;1(TI1FP1)
        TIM5->SMCR|=7<<0;           //ía2&#191;ê±&#214;ó&#196;£ê&#189;1
       
        TIM_TimeBaseInitStruct.TIM_ClockDivision=0;
        TIM_TimeBaseInitStruct.TIM_CounterMode=TIM_CounterMode_Up;
        TIM_TimeBaseInitStruct.TIM_Period=59999;
        TIM_TimeBaseInitStruct.TIM_Prescaler=1399;//1s
        TIM_TimeBaseInit(TIM3,&TIM_TimeBaseInitStruct);
        TIM_SelectOnePulseMode(TIM3,TIM_OPMode_Single);//μ¥&#194;&#246;3&#229;&#196;£ê&#189;£&#172;μ¥ò&#187;&#194;&#246;3&#229;
       
        TIM_ITConfig(TIM3,TIM_IT_Update,ENABLE);//&#214;D&#182;&#207;ê1&#196;ü

       
        NVIC_InitStruct.NVIC_IRQChannel=TIM3_IRQn;
        NVIC_InitStruct.NVIC_IRQChannelCmd=ENABLE;
        NVIC_InitStruct.NVIC_IRQChannelPreemptionPriority=1;
        NVIC_InitStruct.NVIC_IRQChannelSubPriority=2;
        NVIC_Init(&NVIC_InitStruct);

        TIM_Cmd(TIM5,ENABLE);             //&#198;&#244;&#182;ˉ&#188;&#198;êy&#198;÷£&#172;CEN=1
        TIM_Cmd(TIM3,ENABLE);
       
F4外部时钟模式还需要设置别的吗,求教

友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。