打印
[技术问答]

第一次接触新唐,NANO100请问为什么进不去外部中断

[复制链接]
2369|6
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
周大侠的|  楼主 | 2017-11-20 21:21 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
uint8_t flagbit=0;


void NVIC_GPIO_Init(void)
{
//        GPIO_SetMode(PA,BIT10|BIT11,GPIO_INT_LOW);//
        GPIO_SetMode(PA,BIT10,GPIO_INT_LOW);//
}
void NVIC_Init(void)
{
        NVIC_GPIO_Init();
        NVIC_EnableIRQ(GPABC_IRQn);//ʹÄÜ
        NVIC_SetPriority(GPABC_IRQn,3);//ÓÅÏȼ¶ÉèÖÃ
}

void GPABC_IRQHandler(void)
{
        if(INIT1_PRES==0)
        {
                Delay_ms(10);
        }
        if(INIT1_PRES)flagbit=1;
        while(INIT1_PRES==0);

        NVIC_ClearPendingIRQ(GPABC_IRQn);


}


沙发
周大侠的|  楼主 | 2017-11-20 21:28 | 只看该作者
没有大婶吗

使用特权

评论回复
板凳
643757107| | 2017-11-21 08:46 | 只看该作者
用的哪个型号啊,这个好像分A和B

使用特权

评论回复
地板
643757107| | 2017-11-21 08:58 | 只看该作者
/**************************************************************************//**
* [url=home.php?mod=space&uid=288409]@file[/url]     main.c
* [url=home.php?mod=space&uid=895143]@version[/url]  V2.10
* $Date: 15/07/20 9:38a $
* [url=home.php?mod=space&uid=247401]@brief[/url]    Use GPIO driver to control the GPIO pin direction and the high/low state,
*           and show how to use GPIO interrupts.
*
* @note
* Copyright (C) 2012 Nuvoton Technology Corp. All rights reserved.
*
******************************************************************************/
#include <stdio.h>
#include "nano100series.h"

/**
* @brief       PortA/PortB/PortC IRQ
*
* @param       None
*
* [url=home.php?mod=space&uid=266161]@return[/url]      None
*
* [url=home.php?mod=space&uid=1543424]@Details[/url]     The PortA/PortB/PortC default IRQ, declared in startup_nano100series.s.
*/
void GPABC_IRQHandler(void)
{
    /* To check if PB.5 interrupt occurred */
    if (PB->ISRC & BIT5) {
        PB->ISRC = BIT5;
        PD0 = PD0 ^ 1;
        printf("PB.5 INT occurred. \n");

    } else {
        /* Un-expected interrupt. Just clear all PORTA, PORTB, PORTC interrupts */
        PA->ISRC = PA->ISRC;
        PB->ISRC = PB->ISRC;
        PC->ISRC = PC->ISRC;
        printf("Un-expected interrupts. \n");
    }
}


/**
* @brief       PortD/PortE/PortF IRQ
*
* @param       None
*
* @return      None
*
* @details     The PortD/PortE/PortF default IRQ, declared in startup_nano100series.s.
*/
void GPDEF_IRQHandler(void)
{
    /* To check if PE.2 interrupt occurred */
    if (PE->ISRC & BIT2) {
        PE->ISRC = BIT2;
        PD0 = PD0 ^ 1;
        printf("PE.2 INT occurred. \n");
    } else {
        /* Un-expected interrupt. Just clear all PORTD, PORTE and PORTF interrupts */
        PD->ISRC = PD->ISRC;
        PE->ISRC = PE->ISRC;
        PF->ISRC = PF->ISRC;
        printf("Un-expected interrupts. \n");
    }
}


/**
* @brief       External INT0 IRQ
*
* @param       None
*
* @return      None
*
* @details     The External INT0(PA.2) default IRQ, declared in startup_nano100series.s.
*/
void EINT0_IRQHandler(void)
{
    /* For PB.14, clear the INT flag */
    PB->ISRC = BIT14;
    PD0 = PD0 ^ 1;
    printf("PB.14 EINT0 occurred. \n");
}


/**
* @brief       External INT1 IRQ
*
* @param       None
*
* @return      None
*
* @details     The External INT1(PF.2) default IRQ, declared in startup_Nano100series.s.
*/
void EINT1_IRQHandler(void)
{
    /* For PB.15, clear the INT flag */
    PB->ISRC = BIT15;
    PD0 = PD0 ^ 1;
    printf("PB.15 EINT1 occurred. \n");
}

void SYS_Init(void)
{
    /* Unlock protected registers */
    SYS_UnlockReg();

    /* Enable external 12MHz HXT */
    CLK_EnableXtalRC(CLK_PWRCTL_HXT_EN_Msk);
    CLK_EnablePLL(CLK_PLLCTL_PLL_SRC_HXT, 96000000);
    /* Waiting for clock ready */
    CLK_WaitClockReady(CLK_CLKSTATUS_HXT_STB_Msk | CLK_CLKSTATUS_PLL_STB_Msk);

    CLK_SetHCLK(CLK_CLKSEL0_HCLK_S_PLL, CLK_HCLK_CLK_DIVIDER(3));

    /* Select IP clock source */
    CLK_SetModuleClock(UART0_MODULE, CLK_CLKSEL1_UART_S_HXT, CLK_UART_CLK_DIVIDER(1));
    /* Enable IP clock */
    CLK_EnableModuleClock(UART0_MODULE);

    /*---------------------------------------------------------------------------------------------------------*/
    /* Init I/O Multi-function                                                                                 */
    /*---------------------------------------------------------------------------------------------------------*/
    /* Set PA multi-function pins for UART0 RXD and TXD */
//    SYS->PA_H_MFP &= ~( SYS_PA_H_MFP_PA15_MFP_Msk | SYS_PA_H_MFP_PA14_MFP_Msk);
//    SYS->PA_H_MFP |= (SYS_PA_H_MFP_PA15_MFP_UART0_TX|SYS_PA_H_MFP_PA14_MFP_UART0_RX);
    SYS->PB_L_MFP &= ~( SYS_PB_L_MFP_PB0_MFP_Msk | SYS_PB_L_MFP_PB1_MFP_Msk);
    SYS->PB_L_MFP |= (SYS_PB_L_MFP_PB1_MFP_UART0_TX|SYS_PB_L_MFP_PB0_MFP_UART0_RX);

    /* Lock protected registers */
    SYS_LockReg();
}

void UART0_Init(void)
{
    /* Reset IP */
    SYS_ResetModule(UART0_RST);
    UART0->BAUD = 0x67;              /* Baud Rate:115200  OSC:12MHz */
    UART0->TLCTL = 0x03;             /* Character len is 8 bits */
}

/*---------------------------------------------------------------------------------------------------------*/
/* MAIN function                                                                                           */
/*---------------------------------------------------------------------------------------------------------*/
int main (void)
{
    int32_t i32Err;

    /* Init System, IP clock and multi-function I/O */
    SYS_Init(); //In the end of SYS_Init() will issue SYS_LockReg() to lock protected register. If user want to write protected register, please issue SYS_UnlockReg() to unlock protected register.

    /* Init UART for printf */
    UART0_Init();

    printf("\n\nCPU [url=home.php?mod=space&uid=72445]@[/url] %dHz\n", SystemCoreClock);

    printf("+--------------------------------------+ \n");
    printf("|    NANO100 GPIO Driver Sample Code   | \n");
    printf("+--------------------------------------+ \n");

    /*-----------------------------------------------------------------------------------------------------*/
    /* GPIO Basic Mode Test --- Use Pin Data Input/Output to control GPIO pin                              */
    /*-----------------------------------------------------------------------------------------------------*/
    printf("  >> Please connect PA.0 and PA.1 first << \n");
    printf("     Press any key to start test by using [Pin Data Input/Output Control] \n\n");
    getchar();

    /* Configure PA.0 as Output mode and PA.1 as Input mode then close it */
    GPIO_SetMode(PA, BIT0, GPIO_PMD_OUTPUT);
    GPIO_SetMode(PA, BIT1, GPIO_PMD_INPUT);

    i32Err = 0;
    printf("  GPIO Output/Input test ...... \n");

    /* Use Pin Data Input/Output Control to pull specified I/O or get I/O pin status */
    PA0 = 0;
    CLK_SysTickDelay(10);   /* wait for IO stable */
    if (PA1 != 0) {
        i32Err = 1;
    }

    PA0 = 1;
    CLK_SysTickDelay(10);   /* wait for IO stable */
    if (PA1 != 1) {
        i32Err = 1;
    }

    if ( i32Err ) {
        printf("  [FAIL] --- Please make sure PA.0 and PA.1 are connected. \n");
    } else {
        printf("  [OK] \n");
    }

    /* Configure PA.0 and PA.1 to default Input mode */
    GPIO_SetMode(PA, BIT0, GPIO_PMD_INPUT);
    GPIO_SetMode(PA, BIT1, GPIO_PMD_INPUT);


    /*-----------------------------------------------------------------------------------------------------*/
    /* GPIO Interrupt Function Test                                                                        */
    /*-----------------------------------------------------------------------------------------------------*/
    printf("\n  GPB5, GPE2, GPB14(EINT0) and GPB15(EINT1) are used to test interrupt\n  and control LED (GPA7)\n");

    /*Configure PA7 for LED control */
    GPIO_SetMode(PA, BIT7, GPIO_PMD_OUTPUT);

    /* Configure PB5 as Input mode and enable interrupt by rising edge trigger */
    GPIO_SetMode(PB, BIT5, GPIO_PMD_INPUT);
    GPIO_ENABLE_PULL_UP(PB, BIT5);
    GPIO_EnableInt(PB, 5, GPIO_INT_RISING);

    NVIC_EnableIRQ(GPABC_IRQn);

    /*  Configure PE2 as Input mode pull-up and enable interrupt by low level trigger */
    GPIO_SetMode(PE, BIT2, GPIO_PMD_INPUT);
    GPIO_ENABLE_PULL_UP(PE, BIT2);
    GPIO_EnableInt(PE, 2, GPIO_INT_LOW);

    NVIC_EnableIRQ(GPDEF_IRQn);

    /* Configure PB14 as EINT0 pin and enable interrupt by falling edge trigger */
    SYS->PB_H_MFP = (SYS->PB_H_MFP & (~0x07000000)) | 0x01000000;
    GPIO_SetMode(PB, BIT14, GPIO_PMD_INPUT);
    GPIO_EnableEINT0(PB, 14, GPIO_INT_FALLING);
    NVIC_EnableIRQ(EINT0_IRQn);

    /* Configure PB15 as EINT1 pin and enable interrupt by rising and falling edge trigger */
    SYS->PB_H_MFP = (SYS->PB_H_MFP & (~0x70000000)) | 0x10000000;
    GPIO_SetMode(PB, BIT15, GPIO_PMD_INPUT);
    GPIO_EnableEINT1(PB, 15, GPIO_INT_BOTH_EDGE);
    NVIC_EnableIRQ(EINT1_IRQn);

    /* Enable interrupt de-bounce function and select de-bounce sampling cycle time */
    GPIO_SET_DEBOUNCE_TIME(GPIO_DBCLKSRC_HCLK, GPIO_DBCLKSEL_1);
    GPIO_ENABLE_DEBOUNCE(PB, BIT5);
    GPIO_ENABLE_DEBOUNCE(PE, BIT2);
    GPIO_ENABLE_DEBOUNCE(PB, BIT14);
    GPIO_ENABLE_DEBOUNCE(PB, BIT15);

    /* Waiting for interrupts */
    while (1);

}


使用特权

评论回复
5
643757107| | 2017-11-21 08:58 | 只看该作者
这个是关于所有IO的中断操作例子。。

使用特权

评论回复
6
zhuotuzi| | 2017-11-21 15:21 | 只看该作者
根据楼上朋友的例子问题解决了吧。

使用特权

评论回复
7
wanduzi| | 2017-11-21 18:56 | 只看该作者
没有配置正确。

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

1

主题

2

帖子

0

粉丝