完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
void MY_CONFIG(void)
{ NVIC_InitTypeDef NVIC_InitStructure; GPIO_InitTypeDef GPIO_InitStructure; tiM_TimeBaseInitTypeDef TIM_TimeBaseStructure; /* TIM4 clock source enable */ RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM4, ENABLE); /* Enable GPIOA, clock */ RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE); GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz; GPIO_Init(GPIOB, &GPIO_InitStructure); TIM_DeInit(TIM4); TIM_TimeBaseStructure.TIM_Period = 100; TIM_TimeBaseStructure.TIM_Prescaler = 0; TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1; TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Down; TIM_TimeBaseInit(TIM4, &TIM_TimeBaseStructure); TIM_SetCounter(TIM4, 100); TIM_ARRPreloadConfig(TIM4, ENABLE); TIM_SelectInputTrigger(TIM4, TIM_TS_TI2FP2); TIM_SelectSlaveMode(TIM4, TIM_SlaveMode_External1); TIM_SetCompare2(TIM4, 100); /*ÉèÖÃ*/ TIM_Cmd(TIM4, ENABLE); TIM_ClearFlag(TIM4, TIM_IT_CC2); TIM_ITConfig(TIM4, TIM_IT_CC2, ENABLE); NVIC_InitStructure.NVIC_IRQChannel = TIM4_IRQn; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 3; NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure); } void TIM4_IRQHandler(void) { int IC2Value; IC2Value = TIM_GetCapture2(TIM4); printf("rn %drn",IC2Value); TIM_ClearFlag(TIM4, TIM_IT_CC2); } 为什么计不了数,感觉中断不起作用 |
|
相关推荐 |
|
你正在撰写答案
如果你是对答案或其他答案精选点评或询问,请使用“评论”功能。
1276 浏览 1 评论
AD7686芯片不传输数据给STM32,但是手按住就会有数据。
1209 浏览 3 评论
2288 浏览 0 评论
如何解决MPU-9250与STM32通讯时,出现HAL_ERROR = 0x01U
1372 浏览 1 评论
hal库中i2c卡死在HAL_I2C_Master_Transmit
1799 浏览 1 评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-11-29 09:23 , Processed in 0.571860 second(s), Total 73, Slave 55 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号