完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
|
|
|
|
数据手册
|
|
|
|
NVIC_InitTypeDef NVIC_InitStructure; GPIO_InitTypeDef GPIO_InitStructure; TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure; TIM_ICInitTypeDef TIM_ICInitStructure; RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM4, ENABLE); RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOB,ENABLE); GPIO_PinAFConfig(GPIOB, GPIO_PinSource6, GPIO_AF_TIM4); GPIO_PinAFConfig(GPIOB, GPIO_PinSource7, GPIO_AF_TIM4); GPIO_StructInit(&GPIO_InitStructure); /* Configure PB.06,07 as encoder input */ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6 | GPIO_Pin_7; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP; GPIO_InitStructure.GPIO_Speed=GPIO_Speed_100MHz; GPIO_Init(GPIOB, &GPIO_InitStructure); NVIC_InitStructure.NVIC_IRQChannel = TIM4_IRQn; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1; NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure); TIM_DeInit(X_ENCODER_TIMER); TIM_TimeBaseStructInit(&TIM_TimeBaseStructure); TIM_TimeBaseStructure.TIM_Prescaler = 0x0; TIM_TimeBaseStructure.TIM_Period = 40000-1; TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1; TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up; TIM_TimeBaseInit(X_ENCODER_TIMER, &TIM_TimeBaseStructure); TIM_EncoderInterfaceConfig(X_ENCODER_TIMER, TIM_EncoderMode_TI12,TIM_ICPolarity_Rising, TIM_ICPolarity_Rising); TIM_ICStructInit(&TIM_ICInitStructure); TIM_ICInitStructure.TIM_ICFilter = X_ICx_FILTER; TIM_ICInit(X_ENCODER_TIMER, &TIM_ICInitStructure); // Clear all pending interrupts TIM_ClearFlag(X_ENCODER_TIMER, TIM_FLAG_Update); TIM_ITConfig(X_ENCODER_TIMER, TIM_IT_Update, ENABLE); X_ENCODER_TIMER->SR = 0xfffe; TIM_Cmd(X_ENCODER_TIMER, ENABLE); |
|
|
|
|
|
|
|
|
|
|
|
你正在撰写答案
如果你是对答案或其他答案精选点评或询问,请使用“评论”功能。
1107 浏览 0 评论
AD7686芯片不传输数据给STM32,但是手按住就会有数据。
1055 浏览 2 评论
2159 浏览 0 评论
如何解决MPU-9250与STM32通讯时,出现HAL_ERROR = 0x01U
1253 浏览 1 评论
hal库中i2c卡死在HAL_I2C_Master_Transmit
1678 浏览 1 评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-11-25 12:27 , Processed in 0.635091 second(s), Total 51, Slave 44 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号