ch32v208外部脈沖計(jì)數(shù)

請(qǐng)問這份代碼有問題嗎,卡在輸入捕獲初始化,跑不起來

void Input_Capture_Init(u16 arr, u16 psc)

{

? ? GPIO_InitTypeDef? ? ? ? GPIO_InitStructure = {0};

? ? TIM_ICInitTypeDef? ? ? ?TIM_ICInitStructure = {0};

? ? TIM_TimeBaseInitTypeDef TIM_TimeBaseInitStructure = {0};

? ? NVIC_InitTypeDef? ? ? ? NVIC_InitStructure = {0};



? ? RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB , ENABLE);

? ? RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM4, ENABLE);


? ? GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6;

? ? GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPD;

? ? GPIO_Init(GPIOB, &GPIO_InitStructure);

? ? GPIO_ResetBits(GPIOB, GPIO_Pin_6);


? ? TIM_TimeBaseInitStructure.TIM_Period = 0xFFFF;

? ? TIM_TimeBaseInitStructure.TIM_Prescaler = 48000 - 1;

? ? TIM_TimeBaseInitStructure.TIM_ClockDivision = TIM_CKD_DIV1;

? ? TIM_TimeBaseInitStructure.TIM_CounterMode = TIM_CounterMode_Up;

? ? TIM_TimeBaseInitStructure.TIM_RepetitionCounter = 0x00;

? ? TIM_TimeBaseInit(TIM4, &TIM_TimeBaseInitStructure);


? ? TIM_ICInitStructure.TIM_Channel = TIM_Channel_1;

? ? TIM_ICInitStructure.TIM_ICPrescaler = TIM_ICPSC_DIV1;

? ? TIM_ICInitStructure.TIM_ICFilter = 0x00;

? ? TIM_ICInitStructure.TIM_ICPolarity = TIM_ICPolarity_Rising;

? ? TIM_ICInitStructure.TIM_ICSelection = TIM_ICSelection_DirectTI;

? ? TIM_ICInit(TIM4, &TIM_ICInitStructure);


//? ? TIM_PWMIConfig(TIM4, &TIM_ICInitStructure);


? ? NVIC_InitStructure.NVIC_IRQChannel = TIM4_IRQn;

? ? NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 2;

? ? NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;

? ? NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;

? ? NVIC_Init(&NVIC_InitStructure);



//? ? TIM_SelectInputTrigger(TIM1, TIM_TS_TI1FP1);

//? ? TIM_SelectSlaveMode(TIM1, TIM_SlaveMode_Reset);

//? ? TIM_SelectMasterSlaveMode(TIM1, TIM_MasterSlaveMode_Enable);

? ? TIM_ITConfig(TIM4, TIM_IT_Update|TIM_IT_CC1 , ENABLE);

? ? TIM_Cmd(TIM4, ENABLE);


}


void TIM4_IRQnHandler (void)

{



? ? printf("111\n");

? ? if (TIM_GetITStatus(TIM4,TIM_IT_CC1) != RESET)? //檢查TIM5更新中斷發(fā)生與否

? ? ? ? {

? ? ? ? printf("222\n");

? ? ? ? }

? ? ?TIM_ClearITPendingBit(TIM4,TIM_IT_CC1|TIM_IT_Update); //清除中斷標(biāo)志位



}





您好,注意中斷函數(shù)需要加中斷聲明,如下圖。附件為參考例程,可以參考一下。

icon_rar.gifCH32V208 輸入捕獲.zip

image.png


只有登錄才能回復(fù),可以選擇微信賬號(hào)登錄

国产91精品新入口,国产成人综合网在线播放,九热这里只有精品,本道在线观看,美女视频a美女视频,韩国美女激情视频,日本美女pvp视频