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); } } |
STM32H5的I3C模块,target rx和tx时,硬件都存在bug
买了别人的开发板,照着教程学了。积累了很多东西,怎么还是觉得空虚呀?
上电RC,电阻1M 电容0.1uf,导致uart失效
stm32编码器模式计数问题
I3C 可仲裁头的IBI中断
2024 STM32全国巡回研讨会成都站 分享
STM32H723VGT6的唯一DFSDM的时钟可以同时输出给2个sigma-delta吗?
AS608指纹模块的判断中断接收的数组有没有应答包的函数,程序卡死
myst账号无法注册,邮箱确认链接点进后显示The validation link you have provided has expired or been
DMA和GPIO外部中断异常
B1 B2 引脚的线都插着,旋转编码器正转反转都是减少,
只拔掉插在B2引脚的线,旋转编码器正转反转都是减少,
只拔插在掉B1引脚的线,没有反应。