最近手头上接到一个LPC824的单片机的项目,娘的,nxp的lib及源码用的人太少了,根本无法与stm32相关的资源相比,搞个gpioo中断用了我两天时间,心里那个火啊~~~~,问了周立功的技术支持,唉,也是强差人意,什么事看来都得自己好研究才行啊。回头说正事,要加一个gpio中断,先参考了一个系统里的INT0,其配置如下:
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
}
大功告成!