include "stm32f4xx.h" // Device headerint16_t Encoder_Count; void Encoder_Init(void) { RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOB,ENABLE); RCC_APB2PeriphClockCmd(RCC_APB2Periph_SYSCFG,ENABLE); GPIO_InitTypeDef GPIO_InitStructure; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN; GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1 | GPIO_Pin_2; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP; GPIO_Init(GPIOB,&GPIO_InitStructure); SYSCFG_EXTILineConfig(EXTI_PortSourceGPIOB,EXTI_PinSource1); //连接 EXTI 中断源 到 PB1 引脚 SYSCFG_EXTILineConfig(EXTI_PortSourceGPIOB,EXTI_PinSource2); //连接 EXTI 中断源 到 PB2 引脚 EXTI_InitTypeDef EXTI_InitStructure; EXTI_InitStructure.EXTI_Line = EXTI_Line1 | EXTI_Line2; EXTI_InitStructure.EXTI_LineCmd = ENABLE; EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt; EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling; EXTI_Init(&EXTI_InitStructure); NVIC_InitTypeDef NVIC_InitStructure; NVIC_InitStructure.NVIC_IRQChannel = EXTI1_IRQn; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1; NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1; NVIC_Init(&NVIC_InitStructure); NVIC_InitStructure.NVIC_IRQChannel = EXTI2_IRQn; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1; NVIC_InitStructure.NVIC_IRQChannelSubPriority = 2; NVIC_Init(&NVIC_InitStructure); } int16_t Encoder_Get(void) { int16_t Temp; Temp = Encoder_Count; Encoder_Count = 0; return Temp; } void EXTI1_IRQHandler(void) { if(EXTI_GetITStatus(EXTI_Line1) == SET) { if(GPIO_ReadInputDataBit(GPIOB,GPIO_Pin_1) == 0) { if(GPIO_ReadInputDataBit(GPIOB,GPIO_Pin_2) == 0) { Encoder_Count --; } } EXTI_ClearITPendingBit(EXTI_Line1); } } void EXTI2_IRQHandler(void) { if(EXTI_GetITStatus(EXTI_Line2) == SET) { if(GPIO_ReadInputDataBit(GPIOB,GPIO_Pin_2) == 0) { if(GPIO_ReadInputDataBit(GPIOB,GPIO_Pin_1) == 0) { Encoder_Count ++; } } EXTI_ClearITPendingBit(EXTI_Line2); } } |
I3C 可仲裁头的IBI中断
2024 STM32全国巡回研讨会成都站 分享
STM32H723VGT6的唯一DFSDM的时钟可以同时输出给2个sigma-delta吗?
AS608指纹模块的判断中断接收的数组有没有应答包的函数,程序卡死
myst账号无法注册,邮箱确认链接点进后显示The validation link you have provided has expired or been
DMA和GPIO外部中断异常
求助:VL53L0在使用一段时间后无法读取数据,已经有好几个模块了,返回的错误代码有-6,-7和-20,这个到底是怎么回事
太阳能电池板清洁小车的能实现的代码程序例子?
MotorControl Workbench 5.4.8
stm32f103rct6上升沿捕捉最小的高电平是多少?
B1 B2 引脚的线都插着,旋转编码器正转反转都是减少,
只拔掉插在B2引脚的线,旋转编码器正转反转都是减少,
只拔插在掉B1引脚的线,没有反应。