[技术问答] 外部中断 上升下降沿触发 没有作用

[复制链接]
 楼主| ansicheng 发表于 2018-9-4 11:20 | 显示全部楼层 |阅读模式
本帖最后由 ansicheng 于 2018-9-4 11:21 编辑

IO口 外部中断 没有作用
NUC131的芯片 PB14引脚

int set_intrupt()
{
        GPIO_SetMode(PB, BIT14, GPIO_PMD_INPUT);  /* 引脚PB14模式准双向 */
        GPIO_EnableInt(PB, 14, GPIO_INT_BOTH_EDGE); /* 上升下降延触发 */
        NVIC_EnableIRQ(GPAB_IRQn);                /* 中断控制器使能 */
        
        NVIC_SetPriority(GPAB_IRQn, 0);
        
        return 0;
}


void GPAB_IRQHandler()
{
        printf("interrupt\n");

}

什么原因,引脚电平变化没有作用
xuanhuanzi 发表于 2018-9-4 18:58 | 显示全部楼层
  1. /**************************************************************************//**
  2. * [url=home.php?mod=space&uid=288409]@file[/url]     main.c
  3. * [url=home.php?mod=space&uid=895143]@version[/url]  V3.00
  4. * $Revision: 7 $
  5. * $Date: 15/01/16 11:44a $
  6. * [url=home.php?mod=space&uid=247401]@brief[/url]    Show the usage of GPIO interrupt function.
  7. * @note
  8. * Copyright (C) 2013 Nuvoton Technology Corp. All rights reserved.
  9. ******************************************************************************/
  10. #include <stdio.h>
  11. #include "NUC131.h"


  12. #define PLL_CLOCK   50000000


  13. /**
  14. * @brief       GPIO PA/PB IRQ
  15. *
  16. * @param       None
  17. *
  18. * [url=home.php?mod=space&uid=266161]@return[/url]      None
  19. *
  20. * [url=home.php?mod=space&uid=1543424]@Details[/url]     The PA/PB default IRQ, declared in startup_NUC131.s.
  21. */
  22. void GPAB_IRQHandler(void)
  23. {
  24.     /* To check if PB.3 interrupt occurred */

  25.     if(GPIO_GET_INT_FLAG(PB, BIT3))
  26.     {
  27.         GPIO_CLR_INT_FLAG(PB, BIT3);
  28.         printf("PB.3 INT occurred.\n");
  29.     }
  30.     else
  31.     {
  32.         /* Un-expected interrupt. Just clear all PA, PB interrupts */
  33.         PA->ISRC = PA->ISRC;
  34.         PB->ISRC = PB->ISRC;
  35.         printf("Un-expected interrupts.\n");
  36.     }
  37. }

  38. /**
  39. * @brief       GPIO PC/PD/PE/PF IRQ
  40. *
  41. * @param       None
  42. *
  43. * @return      None
  44. *
  45. * @details     The PC/PD/PE/PF default IRQ, declared in startup_NUC131.s.
  46. */
  47. void GPCDEF_IRQHandler(void)
  48. {
  49.     /* To check if PE.5 interrupt occurred */
  50.     if(GPIO_GET_INT_FLAG(PE, BIT5))
  51.     {
  52.         GPIO_CLR_INT_FLAG(PE, BIT5);
  53.         printf("PE.5 INT occurred.\n");
  54.     }
  55.     else
  56.     {
  57.         /* Un-expected interrupt. Just clear all PC, PD, PE and PF interrupts */
  58.         PC->ISRC = PC->ISRC;
  59.         PD->ISRC = PD->ISRC;
  60.         PE->ISRC = PE->ISRC;
  61.         PF->ISRC = PF->ISRC;
  62.         printf("Un-expected interrupts.\n");
  63.     }
  64. }

  65. void SYS_Init(void)
  66. {
  67.     /*---------------------------------------------------------------------------------------------------------*/
  68.     /* Init System Clock                                                                                       */
  69.     /*---------------------------------------------------------------------------------------------------------*/

  70.     /* Enable Internal RC 22.1184MHz clock */
  71.     CLK_EnableXtalRC(CLK_PWRCON_OSC22M_EN_Msk);

  72.     /* Waiting for Internal RC clock ready */
  73.     CLK_WaitClockReady(CLK_CLKSTATUS_OSC22M_STB_Msk);

  74.     /* Switch HCLK clock source to Internal RC and HCLK source divide 1 */
  75.     CLK_SetHCLK(CLK_CLKSEL0_HCLK_S_HIRC, CLK_CLKDIV_HCLK(1));

  76.     /* Enable external XTAL 12MHz clock */
  77.     CLK_EnableXtalRC(CLK_PWRCON_XTL12M_EN_Msk);

  78.     /* Waiting for external XTAL clock ready */
  79.     CLK_WaitClockReady(CLK_CLKSTATUS_XTL12M_STB_Msk);

  80.     /* Set core clock as PLL_CLOCK from PLL */
  81.     CLK_SetCoreClock(PLL_CLOCK);

  82.     /* Enable UART module clock */
  83.     CLK_EnableModuleClock(UART0_MODULE);

  84.     /* Select UART module clock source */
  85.     CLK_SetModuleClock(UART0_MODULE, CLK_CLKSEL1_UART_S_HXT, CLK_CLKDIV_UART(1));

  86.     /*---------------------------------------------------------------------------------------------------------*/
  87.     /* Init I/O Multi-function                                                                                 */
  88.     /*---------------------------------------------------------------------------------------------------------*/

  89.     /* Set GPB multi-function pins for UART0 RXD(PB.0) and TXD(PB.1) */
  90.     SYS->GPB_MFP &= ~(SYS_GPB_MFP_PB0_Msk | SYS_GPB_MFP_PB1_Msk);
  91.     SYS->GPB_MFP |= (SYS_GPB_MFP_PB0_UART0_RXD | SYS_GPB_MFP_PB1_UART0_TXD);

  92. }

  93. void UART0_Init(void)
  94. {
  95.     /*---------------------------------------------------------------------------------------------------------*/
  96.     /* Init UART                                                                                               */
  97.     /*---------------------------------------------------------------------------------------------------------*/
  98.     /* Reset UART0 module */
  99.     SYS_ResetModule(UART0_RST);

  100.     /* Configure UART0 and set UART0 Baudrate */
  101.     UART_Open(UART0, 115200);
  102. }

  103. /*---------------------------------------------------------------------------------------------------------*/
  104. /* MAIN function                                                                                           */
  105. /*---------------------------------------------------------------------------------------------------------*/
  106. int main(void)
  107. {
  108.     /* Unlock protected registers */
  109.     SYS_UnlockReg();

  110.     /* Init System, peripheral clock and multi-function I/O */
  111.     SYS_Init();

  112.     /* Lock protected registers */
  113.     SYS_LockReg();

  114.     /* Init UART0 for printf */
  115.     UART0_Init();

  116.     printf("\n\nCPU [url=home.php?mod=space&uid=72445]@[/url] %d Hz\n", SystemCoreClock);
  117.     printf("+------------------------------------------------+\n");
  118.     printf("|    GPIO PB.3 and PE.5 Interrupt Sample Code    |\n");
  119.     printf("+------------------------------------------------+\n\n");

  120.     /*-----------------------------------------------------------------------------------------------------*/
  121.     /* GPIO Interrupt Function Test                                                                        */
  122.     /*-----------------------------------------------------------------------------------------------------*/
  123.     printf("PB.3 and PE.5 are used to test interrupt ......\n");

  124.     /* Configure PB.3 as Input mode and enable interrupt by rising edge trigger */
  125.     GPIO_SetMode(PB, BIT3, GPIO_PMD_INPUT);
  126.     GPIO_EnableInt(PB, 3, GPIO_INT_RISING);
  127.     NVIC_EnableIRQ(GPAB_IRQn);

  128.     /*  Configure PE.5 as Quasi-bidirection mode and enable interrupt by falling edge trigger */
  129.     GPIO_SetMode(PE, BIT5, GPIO_PMD_QUASI);
  130.     GPIO_EnableInt(PE, 5, GPIO_INT_FALLING);
  131.     NVIC_EnableIRQ(GPCDEF_IRQn);

  132.     /* Waiting for interrupts */
  133.     while(1);
  134. }

  135. /*** (C) COPYRIGHT 2013 Nuvoton Technology Corp. ***/
xidaole 发表于 2018-9-22 07:34 | 显示全部楼层
本帖最后由 xidaole 于 2018-9-22 07:35 编辑

NUC100 上使用也有这个毛病,引脚设定为GPIO方式,PB14 触发不了中断,其它同端引脚,中断正常。使用查询方式,发现PB14有中断标记!!!
yiyigirl2014 发表于 2018-9-22 13:13 | 显示全部楼层
你中断里要清理啊,不然一直没有出去。
yiyigirl2014 发表于 2018-9-22 13:14 | 显示全部楼层
不清理中断标志,一直没有退出第一个中断,也就没法产生后面的中断了。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

3

主题

6

帖子

0

粉丝
快速回复 在线客服 返回列表 返回顶部