你的浏览器版本过低,可能导致网站不能正常访问!
为了你能正常使用网站功能,请使用这些浏览器。

STM32F0 程序移到STM32G0 PB3边沿中断不运行

[复制链接]
challenger365 提问时间:2024-2-29 14:11 / 未解决
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);
}

STM32F0 程序移到STM32G0 PB3边沿中断不运行.docx (15.26 KB, 下载次数: 0)
收藏 评论0 发布时间:2024-2-29 14:11

举报

0个回答
关于
我们是谁
投资者关系
意法半导体可持续发展举措
创新与技术
意法半导体官网
联系我们
联系ST分支机构
寻找销售人员和分销渠道
社区
媒体中心
活动与培训
隐私策略
隐私策略
Cookies管理
行使您的权利
官方最新发布
STM32Cube扩展软件包
意法半导体边缘AI套件
ST - 理想汽车豪华SUV案例
ST意法半导体智能家居案例
STM32 ARM Cortex 32位微控制器
关注我们
st-img 微信公众号
st-img 手机版