查看: 3775|回复: 0

[分享] LPC824 gpio中断配置指南

[复制链接]
  • TA的每日心情
    开心
    2025-7-11 08:53
  • 签到天数: 301 天

    连续签到: 2 天

    [LV.8]以坛为家I

    3873

    主题

    7477

    帖子

    0

    管理员

    Rank: 9Rank: 9Rank: 9

    积分
    39276
    最后登录
    2025-7-21
    发表于 2020-5-12 14:48:12 | 显示全部楼层 |阅读模式
    LPC824 gpio中断配置指南


    1. gpio4 做为PIN_INT0_IRQn

    中断初始化:

    //gpio4 作为eint0

        NVIC_ClearPendingIRQ(PIN_INT0_IRQn);
        NVIC_EnableIRQ(PIN_INT0_IRQn);  
        //NVIC_EnableIRQ(PIN_INT4_IRQn);  
        LPC_SYSCON->PDRUNCFG  &= ~WDT_OSC_PD;                               /* 运行WDT                      */
        /*PIO4 低功耗初始化*/
        LPC_SYSCON->PINTSEL0 = 4;      
        // 中断0 对应的边缘触发
        LPC_PIN_INT->ISEL   &= ~0x1;                                         /* 边沿触发                     */
         LPC_PIN_INT->IENF   |=  0x1;                     // enable 中断0
        LPC_PIN_INT->IST =0xff;                    //清所有中断状态reg


    中断服务进程如下:

    void PIN_INT0_IRQHandler (void)
    {
        LPC_PIN_INT->IST |=  (1<<0);                                          
    }

    2.  gpio28做为PIN_INT4_IRQn配置如下:

    #if 1 //add liuxd 20190327 reload vbus wakeup system
        NVIC_ClearPendingIRQ(PIN_INT4_IRQn);  
        axp173_irq_init();  
        LPC_SYSCON->SYSAHBCLKCTRL |= (1 << 6);  
        LPC_GPIO_PORT->DIR0 &= ~(1<<28);         // io28 input  
        NVIC_EnableIRQ(PIN_INT4_IRQn);
        LPC_SYSCON->PINTSEL4 = 28;
        LPC_PIN_INT->ISEL   &= ~0x10;         /* 边沿触发                     */
        LPC_PIN_INT->IENF   |=  0x10;            //使用中断4
        LPC_PIN_INT->IST = 0xff;                 //clear INT status
    #endif

    void PIN_INT4_IRQHandler (void)
    {
        LPC_PIN_INT->IST |=  (1<<4);     
    }

    中断发生后一定要清中断,要不中断被占用后将不再发生中断!

    本案中用的pmu为axp173,可它的IRQ一直没有发生,原来不是中断被占用后将不再发生中断的原因,将中断全部清一下后ok

    清中断如下:

    static void axp173_irq_init(void)
    {
          char buff[2] = {0};
          buff[0] = 8;
          i2c2_write_nbytes(0x34,0x40,buff,1); // INT Enable
          buff[0] = 8;
          i2c2_write_nbytes(0x34,0x41,buff,1); // INT Enable
          buff[0] = 0;
          i2c2_write_nbytes(0x34,0x42,buff,1); // INT Enable
          buff[0] = 0;
          i2c2_write_nbytes(0x34,0x43,buff,1); // INT Enable
          
          buff[0] = 0xff;
          i2c2_write_nbytes(0x34,0x44,buff,1); //clear INT status
          buff[0] = 0xff;
          i2c2_write_nbytes(0x34,0x45,buff,1); //clear INT status
          buff[0] = 0xff;
          i2c2_write_nbytes(0x34,0x46,buff,1); //clear INT status
          buff[0] = 0xff;
          i2c2_write_nbytes(0x34,0x47,buff,1); //clear INT status
    }

    大功告成!


    文章出处:CSDN

    qiandao qiandao
    回复

    使用道具 举报

    您需要登录后才可以回帖 注册/登录

    本版积分规则

    关闭

    站长推荐上一条 /3 下一条

    Archiver|手机版|小黑屋|恩智浦技术社区

    GMT+8, 2025-7-21 17:13 , Processed in 0.079672 second(s), 19 queries , MemCache On.

    Powered by Discuz! X3.4

    Copyright © 2001-2024, Tencent Cloud.

    快速回复 返回顶部 返回列表