STM32F0 PB3中断部分程序: void EXTI2_3_IRQHandler(void) { if((EXTI->R & ((uint32_t)0x00000008)) != 0) /* Check line 3 has triggered the IT */ { printf("EXTI2_3_IRQHandlerR=%d\r\n",(EXTI->R & ((uint32_t)0x00000008))); 。。。。。。。。。。。 /* Clear the EXTI line 3 pending bit */ EXTI->R = ((uint32_t)0x00000008); // printf("EXTI2_3_IRQHandler \r\n"); } } void init_zerox_pin(void) { GPIO_InitTypeDef GPIO_InitStruct = {0}; __HAL_RCC_GPIOB_CLK_ENABLE(); /*Configure GPIO pin : PB3 */ GPIO_InitStruct.Pin = GPIO_PIN_3; GPIO_InitStruct.Mode = GPIO_MODE_INPUT; GPIO_InitStruct.Pull = GPIO_NOPULL; HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); } void config_exti_line3_to_zerox(unsigned char enable_disable) { /* Enable SYSCFG clock */ RCC->APB2ENR |= RCC_APB2ENR_SYSCFGEN; /* Connect EXTI3 Line to PB3 pin */ uint32_t tmp = 0x00; tmp = ((uint32_t)0x0F) << (0x04 * (((uint8_t)0x03) & (uint8_t)0x03)); //(uint8_t)0x03)B3 SYSCFG->EXTICR[((uint8_t)0x03) >> 0x02] &= ~tmp; SYSCFG->EXTICR[((uint8_t)0x03) >> 0x02] |= (((uint32_t)((uint8_t)0x01)) << (0x04 * (((uint8_t)0x03) & (uint8_t)0x03))); /* Configure EXTI3 line */ tmp = (uint32_t)EXTI_BASE; if(enable_disable == ENABLE) { printf("config_exti_line3:ENABLE\r\n"); /* Clear EXTI line configuration */ EXTI->IMR &= ~((uint32_t)0x00000008); EXTI->EMR &= ~((uint32_t)0x00000008); tmp += 0x00; *(__IO uint32_t *) tmp |= ((uint32_t)0x00000008); /* Clear Rising Falling edge configuration */ EXTI->RTSR &= ~((uint32_t)0x00000008); EXTI->FTSR &= ~((uint32_t)0x00000008); /* Select the trigger for the selected interrupts */ tmp = (uint32_t)EXTI_BASE; /* falling edge set */ tmp += 0x0C; //EXTI_FTSR: Address offset: 0x0C *(__IO uint32_t *) tmp |= ((uint32_t)0x00000008); } else { printf("config_exti_line33ISABLE\r\n"); tmp += 0x00; /* Disable the selected external lines */ *(__IO uint32_t *) tmp &= ~((uint32_t)0x00000008); } /* Configure NVIC for External Interrupt */ /* Enable Interrupt on EXTI2_3 */ NVIC_EnableIRQ(EXTI2_3_IRQn); /* Set priority for EXTI2_3 */ NVIC_SetPriority(EXTI2_3_IRQn,0); } 更改为STM32G0后,程序如下: void EXTI2_3_IRQHandler(void) { if((EXTI->FPR1 & ((uint32_t)0x00000008)) != 0) /* Check line 3 has triggered the IT */ { printf("EXTI2_3_IRQHandler:FPR1=%d\r\n",(EXTI->FPR1 & ((uint32_t)0x00000008))); 。。。。。。。。。。。 /* Clear the EXTI line 3 pending bit */ EXTI->FPR1 = ((uint32_t)0x00000008); // printf("EXTI2_3_IRQHandler \r\n"); } else if((EXTI->RPR1 & ((uint32_t)0x00000008)) != 0) { printf("EXTI->RPR1 = ((uint32_t)0x00000008)\r\n"); EXTI->RPR1 = ((uint32_t)0x00000008); } } void init_zerox_pin(void) { GPIO_InitTypeDef GPIO_InitStruct = {0}; __HAL_RCC_GPIOB_CLK_ENABLE(); /*Configure GPIO pin : PB3 */ GPIO_InitStruct.Pin = GPIO_PIN_3; GPIO_InitStruct.Mode = GPIO_MODE_INPUT; GPIO_InitStruct.Pull = GPIO_NOPULL; HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); } void config_exti_line3_to_zerox(unsigned char enable_disable) { /* Enable SYSCFG clock */ #if 0 RCC->APB2ENR |= RCC_APB2ENR_SYSCFGEN; #else // RCC->APBENR2 |= RCC_APBENR2_SYSCFGEN; __HAL_RCC_SYSCFG_CLK_ENABLE(); #endif /* Connect EXTI3 Line to PB3 pin */ uint32_t tmp = 0x00; #if 0 tmp = ((uint32_t)0x0F) << (0x04 * (((uint8_t)0x03) & (uint8_t)0x03)); SYSCFG->EXTICR[((uint8_t)0x03) >> 0x02] &= ~tmp; SYSCFG->EXTICR[((uint8_t)0x03) >> 0x02] |= (((uint32_t)((uint8_t)0x01)) << (0x04 * (((uint8_t)0x03) & (uint8_t)0x03))); #else tmp = ((uint32_t)0x0F) << (0x08 * (((uint8_t)0x03) & (uint8_t)0x03)); EXTI->EXTICR[((uint8_t)0x03) >> 0x02] &= ~tmp; EXTI->EXTICR[((uint8_t)0x03) >> 0x02] |= (((uint32_t)((uint8_t)0x01)) << (0x08 * (((uint8_t)0x03) & (uint8_t)0x03))); #endif /* Configure EXTI3 line */ tmp = (uint32_t)EXTI_BASE; if(enable_disable == ENABLE) { printf("config_exti_line3:ENABLE\r\n"); /* Clear EXTI line configuration */ #if 0 EXTI->IMR &= ~((uint32_t)0x00000008); EXTI->EMR &= ~((uint32_t)0x00000008); #else EXTI->IMR1 &= ~((uint32_t)0x00000008); EXTI->EMR1 &= ~((uint32_t)0x00000008); #endif tmp += 0x00; *(__IO uint32_t *) tmp |= ((uint32_t)0x00000008); /* Clear Rising Falling edge configuration */ #if 0 EXTI->RTSR &= ~((uint32_t)0x00000008); EXTI->FTSR &= ~((uint32_t)0x00000008); #else EXTI->RTSR1 &= ~((uint32_t)0x00000008); EXTI->FTSR1 &= ~((uint32_t)0x00000008); #endif /* Select the trigger for the selected interrupts */ tmp = (uint32_t)EXTI_BASE; /* falling edge set */ tmp += 0x04; //EXTI_FTSR1:Address offset: 0x04 *(__IO uint32_t *) tmp |= ((uint32_t)0x00000008); } else { printf("config_exti_line33ISABLE\r\n"); tmp += 0x00; /* Disable the selected external lines */ *(__IO uint32_t *) tmp &= ~((uint32_t)0x00000008); } /* Configure NVIC for External Interrupt */ /* Enable Interrupt on EXTI2_3 */ NVIC_EnableIRQ(EXTI2_3_IRQn); /* Set priority for EXTI2_3 */ NVIC_SetPriority(EXTI2_3_IRQn,0); } |
STM32U575 LPBAM中I2C的Sequence Number如何理解
《2024 ST工业峰会》心得分享:
免费试用|领取你的STM32G491,完成你的开发计划
STM32U5退出stop2模式后进入HardFault_Handler
STM32MP1和STM32MP2有什么不同
2024STM32巡回研讨会 北京站 参会心得
2024年STM32巡回研讨会--打卡西安站
ST全国研讨会参会总结
2024 STM32巡回研讨会 杭州站 参会心得
ST研讨会收官之战,上海场打卡