完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
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=%drn",(EXTI->R ((uint32_t)0x00000008))); 。。。。。。。。。。。 /* Clear the EXTI line 3 pending bit */ EXTI->R = ((uint32_t)0x00000008); // printf("EXTI2_3_IRQHandler rn"); } } 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:ENABLErn"); /* 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_line33ISABLErn"); 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=%drn",(EXTI->FPR1 ((uint32_t)0x00000008))); 。。。。。。。。。。。 /* Clear the EXTI line 3 pending bit */ EXTI->FPR1 = ((uint32_t)0x00000008); // printf("EXTI2_3_IRQHandler rn"); } else if((EXTI->RPR1 ((uint32_t)0x00000008)) != 0) { printf("EXTI->RPR1 = ((uint32_t)0x00000008)rn"); 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:ENABLErn"); /* 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_line33ISABLErn"); 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); } 移植之前用的是STM32F030芯片,用的都是早期寄存器弄的驱动,程序运行都正常。这部份边沿中断程序,移植到STM32G070上时, 直接不 运行。难道是STM32G070上什么寄存器配制,没配到位吗?请哪位大神帮我看看,谢谢!!! |
|
相关推荐
1个回答
|
|
您在STM32F0上的中断处理函数可能无法在STM32G070上运行的原因有多种可能性,例如:
1. 中断号不匹配:STM32F0和STM32G070有不同的中断号。请确保在将程序移植到STM32G070时,中断号已正确地更新。 2. 中断优先级不正确:中断优先级设置可能不同于STM32F0到STM32G070。请确保中断优先级设置正确。 3. 中断处理函数命名不正确:请确保将中断处理函数的命名更改为适用于STM32G070。 4. 时钟配置不正确:请确保为STM32G070正确配置了系统和外设时钟。 5. EXTI配置不正确:请确保将外部中断配置为正确的管脚,并正确将其连接到STM32G070上。 6. printf函数使用问题:在某些情况下,printf函数在中断处理函数中可能会导致问题。请确保在中断处理函数中正确使用此函数。 综上所述,移植STM32F030程序到STM32G070上的中断无法运行的原因可能是由于多种因素导致的。您需要仔细检查并解决这些可能的问题。 |
|
|
|
你正在撰写答案
如果你是对答案或其他答案精选点评或询问,请使用“评论”功能。
2162 浏览 1 评论
AD7686芯片不传输数据给STM32,但是手按住就会有数据。
1997 浏览 3 评论
4593 浏览 0 评论
如何解决MPU-9250与STM32通讯时,出现HAL_ERROR = 0x01U
2140 浏览 1 评论
hal库中i2c卡死在HAL_I2C_Master_Transmit
2659 浏览 1 评论
浏览过的版块 |
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-12-24 16:29 , Processed in 1.000746 second(s), Total 72, Slave 56 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号