void TIM_Input_Cap(void) { TIM_TimeBaseInitTypeDef TIM_BaseInitStructure; //¶¨ÒåÁ½¸ö½á¹¹Ìå±äÁ¿ TIM_ICInitTypeDef TIM_ICInitStructure; GPIO_InitTypeDef GPIO_InitStructure; NVIC_InitTypeDef NVIC_InitStructure; RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3,ENABLE);//ʹÄܶ¨Ê±Æ÷ʱÖÓ RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE); // RCC_APB2PeriphClockCmd(RCC_AHBPeriph_CRC, ENABLE); // ??AFIO?? GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_40MHz; GPIO_Init(GPIOA, &GPIO_InitStructure); GPIO_PinAFConfig(GPIOA, GPIO_PinSource6, GPIO_AF_TIM3); TIM_BaseInitStructure.TIM_Period = 1000; //0.1s //¼ÆÊý³¤¶È TIM_BaseInitStructure.TIM_Prescaler = 0; //0.1ms TIM_BaseInitStructure.TIM_ClockDivision = TIM_CKD_DIV1; TIM_BaseInitStructure.TIM_CounterMode = TIM_CounterMode_Up; TIM_ARRPreloadConfig(TIM3, DISABLE);// ?? ARR?????? TIM_TimeBaseInit(TIM3, &TIM_BaseInitStructure); //³õʼ»¯²ÎÊý TIM_ClearFlag(TIM3, TIM_FLAG_Update); TIM_ITConfig( TIM3, TIM_IT_Update, DISABLE ); TIM_ICInitStructure.TIM_Channel = TIM_Channel_1; //????1 TIM_ICInitStructure.TIM_ICPolarity = TIM_ICPolarity_Falling; //??????? TIM_ICInitStructure.TIM_ICSelection = TIM_ICSelection_DirectTI; // ?????? TIM_ICInitStructure.TIM_ICPrescaler = TIM_ICPSC_DIV1; //???????????????? TIM_ICInitStructure.TIM_ICFilter = 0x6; TIM_ICInit(TIM3, &TIM_ICInitStructure); TIM_SelectInputTrigger(TIM3, TIM_TS_TI1FP1); TIM_SelectSlaveMode(TIM3, TIM_SlaveMode_Reset); TIM_SelectMasterSlaveMode(TIM3, TIM_MasterSlaveMode_Enable); TIM_ClearFlag( TIM3, TIM_FLAG_CC1 ); TIM_ARRPreloadConfig(TIM3, ENABLE); NVIC_PriorityGroupConfig(NVIC_PriorityGroup_0); NVIC_InitStructure.NVIC_IRQChannel = TIM3_IRQn; //???? NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0; //?????0 NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1; //?????1 NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; //???? NVIC_Init(&NVIC_InitStructure); //???? TIM_Cmd(TIM3,ENABLE); //´ò¿ªÖÐ¶Ï TIM_ITConfig(TIM3, TIM_IT_CC1, ENABLE); //ʹÄÜÖÐ¶Ï } void TIM3_IRQHandler(void) { TIM_ClearITPendingBit(TIM3, TIM_IT_CC1); /* Get the Input Capture value */ //capture_number = TIM_GetCapture2(TIM2); capture_number=capture_number+1; if(capture_number>3000) {capture_number1=capture_number1+1; capture_number =0;} if(capture_number1>60) {capture_number1 =0;} } 我用的是STM32L15系列的单片机,程序一直进不到捕获中断里,当我把 TIM_Cmd(TIM3,ENABLE); //´ò¿ªÖÐ¶Ï TIM_ITConfig(TIM3, TIM_IT_CC1, ENABLE); //ʹÄÜÖÐ¶Ï 改为 TIM_Cmd(TIM3,ENABLE); //´ò¿ªÖÐ¶Ï TIM_ITConfig(TIM3, TIM_IT_CC2, ENABLE); //ʹÄÜÖÐ¶Ï 时,当不给输入波形,它又会自动进入中断,不知道出了什么问题,请哪位高手能给个解答吧,已经好几天都这种情况了。 |
STM32L151RDT6 SDIO读写SD卡 FIFO下溢错误,不知是什么原因
STM32L152 RTC唤醒STOP mode问题
STM32L152系列自带LCD驱动段码液晶屏,怎么驱动想要亮的段亮
STM32L151为何FLASH擦除后全是是0x00?
求助!!STM32L151中的RTC唤醒(wake up)中断问题
STM32L152普通I/O模拟SPI驱动W25Q16问题
STM32L152开发板原理图及说明文档
STM32L1系列,如何释放PA15为普通GPIO端口
STM32L151读取W25Q16的ID错误,请帮忙看看是什么原因
STM32L151 STOP模式唤醒程序跑哪儿了
RE:我用的是STM32L15系列的单片机,程序一直进不到捕获中断里