[技术问答] M451 GPIO产生外部中断 一直进不去中断。

[复制链接]
1787|8
 楼主| 杨登辉 发表于 2018-11-16 08:57 | 显示全部楼层 |阅读模式
void Button_Init(void)
{
                //CLK_EnableModuleClock();
                SYS_ResetModule(GPIO_RST);
                GPIO_SetMode(PE,BIT2,GPIO_MODE_INPUT);
                GPIO_EnableInt(PE,BIT2,GPIO_INT_FALLING);
                NVIC_SetPriorityGrouping(4);       
                NVIC_EnableIRQ(GPE_IRQn);//EINT4_IRQn
}
void EINT4_IRQHandler(void)
{
        LED_On(1);
}
 楼主| 杨登辉 发表于 2018-11-16 09:42 | 显示全部楼层
已经解决
643757107 发表于 2018-11-16 10:12 | 显示全部楼层
579175bee27a293a43.png
缺乏这种操作
zhuotuzi 发表于 2018-11-16 11:56 | 显示全部楼层
这个管脚是中断4还是普通GPIO中断?不过这种也要在里面清理中断标志位吧
稳稳の幸福 发表于 2018-11-16 22:22 | 显示全部楼层
清理标志位
734774645 发表于 2018-11-16 23:43 | 显示全部楼层
我有个好奇,PE上是不是也有普通GPIO中断,那么跟这个EINT中断共存吗
heisexingqisi 发表于 2018-11-18 12:16 | 显示全部楼层
这个芯片的串口好用不
huahuagg 发表于 2018-11-18 19:13 | 显示全部楼层
  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/09/02 10:04a $
  6. * [url=home.php?mod=space&uid=247401]@brief[/url]    Show the usage of GPIO external interrupt function and de-bounce function.
  7. * @note
  8. * Copyright (C) 2013~2015 Nuvoton Technology Corp. All rights reserved.
  9. ******************************************************************************/
  10. #include <stdio.h>
  11. #include "M451Series.h"


  12. #define PLLCTL_SETTING  CLK_PLLCTL_72MHz_HXT
  13. #define PLL_CLOCK       72000000


  14. /**
  15. * @brief       External INT0 IRQ
  16. *
  17. * @param       None
  18. *
  19. * [url=home.php?mod=space&uid=266161]@return[/url]      None
  20. *
  21. * [url=home.php?mod=space&uid=1543424]@Details[/url]     The External INT0 default IRQ, declared in startup_M451Series.s.
  22. */
  23. void EINT0_IRQHandler(void)
  24. {

  25.     /* To check if PA.0 external interrupt occurred */
  26.     if(GPIO_GET_INT_FLAG(PA, BIT0))
  27.     {
  28.         GPIO_CLR_INT_FLAG(PA, BIT0);
  29.         printf("PA.0 EINT0 occurred.\n");
  30.     }

  31.     /* To check if PD.2 external interrupt occurred */
  32.     if(GPIO_GET_INT_FLAG(PD, BIT2))
  33.     {
  34.         GPIO_CLR_INT_FLAG(PD, BIT2);
  35.         printf("PD.2 EINT0 occurred.\n");
  36.     }

  37. }

  38. /**
  39. * @brief       External INT1 IRQ
  40. *
  41. * @param       None
  42. *
  43. * @return      None
  44. *
  45. * @details     The External INT1 default IRQ, declared in startup_M451Series.s.
  46. */
  47. void EINT1_IRQHandler(void)
  48. {

  49.     /* To check if PB.0 external interrupt occurred */
  50.     if(GPIO_GET_INT_FLAG(PB, BIT0))
  51.     {
  52.         GPIO_CLR_INT_FLAG(PB, BIT0);
  53.         printf("PB.0 EINT1 occurred.\n");
  54.     }

  55. }

  56. void SYS_Init(void)
  57. {
  58.     /*---------------------------------------------------------------------------------------------------------*/
  59.     /* Init System Clock                                                                                       */
  60.     /*---------------------------------------------------------------------------------------------------------*/

  61.     /* Enable HIRC clock (Internal RC 22.1184MHz) */
  62.     CLK_EnableXtalRC(CLK_PWRCTL_HIRCEN_Msk);

  63.     /* Wait for HIRC clock ready */
  64.     CLK_WaitClockReady(CLK_STATUS_HIRCSTB_Msk);

  65.     /* Select HCLK clock source as HIRC and and HCLK source divider as 1 */
  66.     CLK_SetHCLK(CLK_CLKSEL0_HCLKSEL_HIRC, CLK_CLKDIV0_HCLK(1));

  67.     /* Enable HXT clock (external XTAL 12MHz) */
  68.     CLK_EnableXtalRC(CLK_PWRCTL_HXTEN_Msk);

  69.     /* Wait for HXT clock ready */
  70.     CLK_WaitClockReady(CLK_STATUS_HXTSTB_Msk);

  71.     /* Set core clock as PLL_CLOCK from PLL */
  72.     CLK_SetCoreClock(PLL_CLOCK);

  73.     /* Enable UART module clock */
  74.     CLK_EnableModuleClock(UART0_MODULE);

  75.     /* Select UART module clock source as HXT and UART module clock divider as 1 */
  76.     CLK_SetModuleClock(UART0_MODULE, CLK_CLKSEL1_UARTSEL_HXT, CLK_CLKDIV0_UART(1));

  77.     /*---------------------------------------------------------------------------------------------------------*/
  78.     /* Init I/O Multi-function                                                                                 */
  79.     /*---------------------------------------------------------------------------------------------------------*/

  80.     /* Set PD multi-function pins for UART0 RXD(PD.0) and TXD(PD.1) */
  81.     SYS->GPD_MFPL &= ~(SYS_GPD_MFPL_PD0MFP_Msk | SYS_GPD_MFPL_PD1MFP_Msk);
  82.     SYS->GPD_MFPL |= (SYS_GPD_MFPL_PD0MFP_UART0_RXD | SYS_GPD_MFPL_PD1MFP_UART0_TXD);

  83.     /* Set PA multi-function pin for EINT0(PA.0) */
  84.     SYS->GPA_MFPL = SYS->GPA_MFPL & (~SYS_GPA_MFPL_PA0MFP_Msk) | SYS_GPA_MFPL_PA0MFP_INT0;

  85.     /* Set PD multi-function pin for EINT0(PD.2) */
  86.     SYS->GPD_MFPL = SYS->GPD_MFPL & (~SYS_GPD_MFPL_PD2MFP_Msk) | SYS_GPD_MFPL_PD2MFP_INT0;

  87.     /* Set PB multi-function pin for EINT1(PB.0) */
  88.     SYS->GPB_MFPL = SYS->GPB_MFPL & (~SYS_GPB_MFPL_PB0MFP_Msk) | SYS_GPB_MFPL_PB0MFP_INT1;

  89. }

  90. void UART0_Init()
  91. {
  92.     /*---------------------------------------------------------------------------------------------------------*/
  93.     /* Init UART                                                                                               */
  94.     /*---------------------------------------------------------------------------------------------------------*/
  95.     /* Reset UART module */
  96.     SYS_ResetModule(UART0_RST);

  97.     /* Configure UART0 and set UART0 baud rate */
  98.     UART_Open(UART0, 115200);
  99. }

  100. /*---------------------------------------------------------------------------------------------------------*/
  101. /* MAIN function                                                                                           */
  102. /*---------------------------------------------------------------------------------------------------------*/
  103. int main(void)
  104. {
  105.     /* Unlock protected registers */
  106.     SYS_UnlockReg();

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

  109.     /* Lock protected registers */
  110.     SYS_LockReg();

  111.     /* Init UART0 for printf */
  112.     UART0_Init();

  113.     printf("\n\nCPU [url=home.php?mod=space&uid=72445]@[/url] %d Hz\n", SystemCoreClock);
  114.     printf("+------------------------------------------------------------+\n");
  115.     printf("|    GPIO EINT0/EINT1 Interrupt and De-bounce Sample Code    |\n");
  116.     printf("+------------------------------------------------------------+\n\n");

  117.     /*-----------------------------------------------------------------------------------------------------*/
  118.     /* GPIO External Interrupt Function Test                                                               */
  119.     /*-----------------------------------------------------------------------------------------------------*/
  120.     printf("EINT0(PA.0 and PD.2) and EINT1(PB.0) are used to test interrupt\n");

  121.     /* Configure PA.0 as EINT0 pin and enable interrupt by falling edge trigger */
  122.     GPIO_SetMode(PA, BIT0, GPIO_MODE_INPUT);
  123.     GPIO_EnableInt(PA, 0, GPIO_INT_FALLING);

  124.     /* Configure PD.2 as EINT0 pin and enable interrupt by rising edge trigger */
  125.     GPIO_SetMode(PD, BIT2, GPIO_MODE_INPUT);
  126.     GPIO_EnableInt(PD, 2, GPIO_INT_RISING);
  127.     NVIC_EnableIRQ(EINT0_IRQn);

  128.     /* Configure PB.0 as EINT1 pin and enable interrupt by falling and rising edge trigger */
  129.     GPIO_SetMode(PB, BIT0, GPIO_MODE_INPUT);
  130.     GPIO_EnableInt(PB, 0, GPIO_INT_BOTH_EDGE);
  131.     NVIC_EnableIRQ(EINT1_IRQn);

  132.     /* Enable interrupt de-bounce function and select de-bounce sampling cycle time is 1024 clocks of LIRC clock */
  133.     GPIO_SET_DEBOUNCE_TIME(GPIO_DBCTL_DBCLKSRC_LIRC, GPIO_DBCTL_DBCLKSEL_1024);
  134.     GPIO_ENABLE_DEBOUNCE(PA, BIT0);
  135.     GPIO_ENABLE_DEBOUNCE(PB, BIT0);
  136.     GPIO_ENABLE_DEBOUNCE(PD, BIT2);

  137.     /* Waiting for interrupts */
  138.     while(1);
  139. }

  140. /*** (C) COPYRIGHT 2013~2015 Nuvoton Technology Corp. ***/
21mengnan 发表于 2018-11-18 21:48 | 显示全部楼层
点灯的入门。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

7

主题

24

帖子

0

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