• 正文
  • 相關(guān)推薦
  • 電子產(chǎn)業(yè)圖譜
申請入駐 產(chǎn)業(yè)圖譜

LPC824 gpio中斷配置指南分享

02/05 16:10
513
加入交流群
掃碼加入
獲取工程師必備禮包
參與熱點資訊討論

今天給大家分享一下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 對應(yīng)的邊緣觸發(fā)
LPC_PIN_INT->ISEL &= ~0x1; /* 邊沿觸發(fā) */
LPC_PIN_INT->IENF |= 0x1; // enable 中斷0
LPC_PIN_INT->IST =0xff; //清所有中斷狀態(tài)reg

中斷服務(wù)進程如下:

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; /* 邊沿觸發(fā) */
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);
}

中斷發(fā)生后一定要清中斷,要不中斷被占用后將不再發(fā)生中斷!
本案中用的pmu為axp173,可它的IRQ一直沒有發(fā)生,原來不是中斷被占用后將不再發(fā)生中斷的原因,將中斷全部清一下后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
}

相關(guān)推薦

電子產(chǎn)業(yè)圖譜