在线时间4818 小时
UID3441752
注册时间2017-11-21
NXP金币75697
TA的每日心情 | 开心 2025-7-11 08:53 |
---|
签到天数: 301 天 连续签到: 2 天 [LV.8]以坛为家I
管理员
  
- 积分
- 40293
- 最后登录
- 2025-9-12
|
LPC824 gpio中断配置指南
今天给大家分享一下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
- }
复制代码
|
|