ZBLOG

void nvic_init(void) { NVIC_InitTypeDef nvic_struct1; NVIC_InitTypeDef nvic_struct2; NVIC_InitTypeDef nvic_struct3; NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1); nvic_struct1.NVIC_IRQChannel = EXTI0_IRQn; nvic_struct1.NVIC_IRQChannelPre...

在这段代码中,存在一些错误的地方:

  1. NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1)被多次调用,这是不必要的。只需要在初始化之前调用一次即可。

  2. nvic_struct3的初始化过程中,使用了错误的宏定义EXTI15_10_IRQn。应该将其改为正确的值EXTI15_10_IRQChannel

下面是修改后的代码:

  1. void nvic_init(void)
  2. {
  3. NVIC_InitTypeDef nvic_struct1;
  4. NVIC_InitTypeDef nvic_struct2;
  5. NVIC_InitTypeDef nvic_struct3;
  6. // 设置优先级分组
  7. NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1);
  8. nvic_struct1.NVIC_IRQChannel = EXTI0_IRQn;
  9. nvic_struct1.NVIC_IRQChannelPreemptionPriority = 0;
  10. nvic_struct1.NVIC_IRQChannelSubPriority = 0;
  11. nvic_struct1.NVIC_IRQChannelCmd = ENABLE;
  12. NVIC_Init(&nvic_struct1);
  13. nvic_struct2.NVIC_IRQChannel = EXTI1_IRQn;
  14. nvic_struct2.NVIC_IRQChannelPreemptionPriority = 1;
  15. nvic_struct2.NVIC_IRQChannelSubPriority = 0;
  16. nvic_struct2.NVIC_IRQChannelCmd = ENABLE;
  17. NVIC_Init(&nvic_struct2);
  18. nvic_struct3.NVIC_IRQChannel = EXTI15_10_IRQn; // 正确修正为 EXTI15_10_IRQChannel
  19. nvic_struct3.NVIC_IRQChannelPreemptionPriority = 2;
  20. nvic_struct3.NVIC_IRQChannelSubPriority = 0;
  21. nvic_struct3.NVIC_IRQChannelCmd = ENABLE;
  22. NVIC_Init(&nvic_struct3);
  23. }

希望以上修改能够解决你的问题。


内容由零声教学AI助手提供,问题来源于学员提问

本站部分文章来源于网络,版权归原作者所有,如有侵权请联系站长删除。
转载请注明出处:https://golang.0voice.com/?id=9143

分享:
扫描分享到社交APP
上一篇
下一篇
发表列表
游客 游客
此处应有掌声~
评论列表

还没有评论,快来说点什么吧~

联系我们

在线咨询: 点击这里给我发消息

微信号:3007537140

上班时间: 10:30-22:30

关注我们
x

注册

已经有帐号?