LPC1549 GPIO Interrupt Not Invoking

cancel
Showing results for 
Search instead for 
Did you mean: 

LPC1549 GPIO Interrupt Not Invoking

1,668 Views
shantanudhar
Contributor III

I a not getting interrupt even after setting configurations. Can anybody help me finding out what wrong am I doing in the code below ?

#defineTEST_INT_GPIO_PORT

(1)

#defineTEST_INT_GPIO_PIN(9)

Chip_GPIO_SetPinDIRInput(LPC_GPIO, TEST_INT_GPIO_PORT/*port*/, TEST_INT_GPIO_PIN/*pin*/);

Chip_PININT_Init(LPC_GPIO_PIN_INT);

Chip_IOCON_PinMuxSet(LPC_IOCON, TEST_INT_GPIO_PORT, TEST_INT_GPIO_PIN, (IOCON_DIGMODE_EN | IOCON_MODE_INACT) );

/* Configure interrupt channel for the GPIO pin in INMUX block */
Chip_INMUX_PinIntSel(PININTCH0, TEST_INT_GPIO_PORT, TEST_INT_GPIO_PIN);

/* Enable interrupt in the NVIC */
NVIC_ClearPendingIRQ(PIN_INT0_IRQn);
NVIC_EnableIRQ(PIN_INT0_IRQn);

/* Configure channel interrupt as edge sensitive and falling edge interrupt */
Chip_PININT_ClearIntStatus(LPC_GPIO_PIN_INT, PININTCH0);
Chip_PININT_SetPinModeEdge(LPC_GPIO_PIN_INT, PININTCH0);
Chip_PININT_EnableIntLow(LPC_GPIO_PIN_INT, PININTCH0);

Now, when I am pressing the SW3 in LPCXpresso1549 board, I am not getting any interrupt generated. What am I doing wrong ?

Labels (3)
11 Replies

477 Views
shantanudhar
Contributor III

I have got that fixed myself. Now, the GPIO interrupt on LPC1549 is working fine. It possibly was a problem with the value of PININTCH(ch) given in the LPCOpen  (file : pinint_15xx.h). After minor calculation, I replaced this value with my custom macro definition:

#define TEST_INT_GPIO_PORT_PIN_VAL ((32*TEST_INT_GPIO_PORT) + TEST_INT_GPIO_PIN)

And some minor modifications. And, it works.all the help 

Thanks for the help and pointers soledad‌ and volkeroth‌.

0 Kudos

477 Views
shantanudhar
Contributor III

I am using lpcopen_2_20_lpcxpresso_nxp_lpcxpresso_1549 library on #LPCXpresso 1549 rev. C board. I wonder if the GPIO pin interrupt of this version of#LPCOpen library really works. Or I need to do any special HW setting to get it work ? I tried with switches SW1 and SW2, but with negative results every time. Any body has any idea ? 

0 Kudos

477 Views
volkeroth
Contributor II

As I neither use an LPCXpresso board nor the LCPOpen libs, I just can tell that it works for me with the settings I posted. Well, actually I use my own mini-libs, so I couldn't directly copy my code and I might have overlooked something that I do somewhere else, but I don't think so. There was no black magic involved. I just forgot to enable the PINT peripheral initially, but that was all.

Again, I would recommend to break and look at the registers step by step. Like: is the pin level visible on IO level, are all register configured as expected, was the interrupt request flag raised etc.

0 Kudos

477 Views
shantanudhar
Contributor III

Here below is my code. Made a small change to get the interrupt generated at port 0 pin 17 (SW1). Still it doesn't work. Any help ?

 

#include <cr_section_macros.h>
#include "chip.h"


extern void delay(int count);
extern void WriteIntWithInterrupt(const int inInt);
extern void WriteCharWithInterrupt(char inChar);
extern void WriteStringWithInterrupt(const char *pStr);


/* GPIO pin for PININT interrupt. This is SW1-WAKE button switch input. */
#define TEST_INPUT_PIN 17 /* GPIO pin number mapped to PININT */
#define TEST_INPUT_PORT 0 /* GPIO port number mapped to PININT */
#define TEST_INPUT_PIN_PORT 0
#define TEST_INPUT_PIN_BIT 17
#define PININT_INDEX 0 /* PININT index used for GPIO mapping */
#define PININT_IRQ_HANDLER    PIN_INT0_IRQHandler /* GPIO interrupt IRQ function name */
#define PININT_NVIC_NAME    PIN_INT0_IRQn /* GPIO interrupt NVIC interrupt name */


/**
* @brief Handle interrupt from GPIO pin or GPIO pin mapped to PININT
* @return Nothing
*/
void PININT_IRQ_HANDLER(void)
{
   //Chip_PININT_ClearIntStatus(LPC_GPIO_PIN_INT, PININTCH(PININT_INDEX));
   Chip_PININT_ClearIntStatus(LPC_GPIO_PIN_INT, 0);
   WriteStringWithInterrupt("Inside SW1 GPIO Interrupt Handler\n");
}


int main(void)
{
   SystemCoreClockUpdate();

 

   /* Initialize GPIO */
   Chip_GPIO_Init(LPC_GPIO);

 

   /* Initialize PININT driver */
   Chip_PININT_Init(LPC_GPIO_PIN_INT);

 

   /* Set pin back to GPIO (on some boards may have been changed to something
   else by Board_Init()) */
   Chip_IOCON_PinMuxSet(LPC_IOCON, TEST_INPUT_PIN_PORT, TEST_INPUT_PIN_BIT,
   (IOCON_DIGMODE_EN | IOCON_MODE_INACT) );

 

   /* Configure GPIO pin as input */
   Chip_GPIO_SetPinDIRInput(LPC_GPIO, TEST_INPUT_PORT, TEST_INPUT_PIN);

 

   /* Configure interrupt channel for the GPIO pin in INMUX block */
   Chip_INMUX_PinIntSel(PININT_INDEX, TEST_INPUT_PORT, TEST_INPUT_PIN);

 

   /* Configure channel interrupt as edge sensitive and falling edge interrupt */
   Chip_PININT_ClearIntStatus(LPC_GPIO_PIN_INT, /*PININTCH(PININT_INDEX)*/0);
   Chip_PININT_SetPinModeEdge(LPC_GPIO_PIN_INT, /*PININTCH(PININT_INDEX)*/0);
   Chip_PININT_EnableIntLow(LPC_GPIO_PIN_INT, /*PININTCH(PININT_INDEX)*/0);

 

   /* Enable interrupt in the NVIC */
   NVIC_ClearPendingIRQ(PININT_NVIC_NAME);
   NVIC_EnableIRQ(PININT_NVIC_NAME);

 

   /* Spin in a loop here. All the work is done in ISR. */
   while (1) {}

 

   return 0;
}

 

Even if I set the interrupt priority NVIC_SetPriority(PIN_INT0_IRQn, int_prio); it don't get an interrupt on press-releasing SW1 button.

0 Kudos

477 Views
volkeroth
Contributor II

Hm, another dumb question: are you sure that the name of the default IRQ handler is "PIN_INT0_IRQHandler" and not "PININT0_IRQHandler"? There is a precompiler switch (USE_LPCOPEN_IRQHANDLER_NAMES) in the default startup which can set either of these. You could check in the name in the map file is the one you are using in the source code.

Apart from that, it usually helps me to look at the peripherals with the debugger. There you can see if all the configurations really are as you expect them.

0 Kudos

477 Views
shantanudhar
Contributor III

I checked in the .map file. And in the .after_vectors section I see the pin interrupt handler is defined as expected as PIN_INT0_IRQHandler(). So, I guess, no issue with the naming. May be something else. I need to dig deep. You please let me know if you find any.

0 Kudos

477 Views
volkeroth
Contributor II

Dumb question, but do you set the interrupt priority somewhere?

I'm not into that LPC API stuff, but broken down to the register access, my initialization for a falling edge interrupt looks like this:

int int_no = 0;                            // Example: use PIN_INT0
int pin_no = 17;                           // Example: use P0.17

int int_prio = 7;

LPC_INMUX->PINTSEL[int_no] = pin_no;       // Assign pin to interrupt
LPC_GPIO_PIN_INT->ISEL = 1UL<<pin_no;      // Select edge sensitive interrupt for pin
LPC_GPIO_PIN_INT->IST = 1UL<<int_no;       // Clear edge interrupt request
LPC_GPIO_PIN_INT->SIENF = 1UL<<int_no;     // Enable falling edge interrupt (for rising edge, you need SIENR)
NVIC_SetPriority(PIN_INT0_IRQn, int_prio); // assuming int_no==0, else you need PIN_INT1_IRQn .. PIN_INT7_IRQn
NVIC_EnableIRQ(PIN_INT0_IRQn, int_prio);   // again, assuming you use INT0

Apart from that, you only need to enable the PINT peripheral in SYSAHBCLKCTRL0.

0 Kudos

477 Views
shantanudhar
Contributor III

I cross checked my code. It doesn't work Volker. And I am still unable to get what wrong is happening. Here below is my code. Made a small change to get the interrupt generated at port 0 pin 17 (SW1). Still it doesn't work. Any help ?

#include <cr_section_macros.h>
#include "chip.h"


extern void delay(int count);
extern void WriteIntWithInterrupt(const int inInt);
extern void WriteCharWithInterrupt(char inChar);
extern void WriteStringWithInterrupt(const char *pStr);


/* GPIO pin for PININT interrupt. This is SW1-WAKE button switch input. */
#define TEST_INPUT_PIN 17 /* GPIO pin number mapped to PININT */
#define TEST_INPUT_PORT 0 /* GPIO port number mapped to PININT */
#define TEST_INPUT_PIN_PORT 0
#define TEST_INPUT_PIN_BIT 17
#define PININT_INDEX 0 /* PININT index used for GPIO mapping */
#define PININT_IRQ_HANDLER    PIN_INT0_IRQHandler /* GPIO interrupt IRQ function name */
#define PININT_NVIC_NAME    PIN_INT0_IRQn /* GPIO interrupt NVIC interrupt name */


/**
* @brief Handle interrupt from GPIO pin or GPIO pin mapped to PININT
* @return Nothing
*/
void PININT_IRQ_HANDLER(void)
{
   //Chip_PININT_ClearIntStatus(LPC_GPIO_PIN_INT, PININTCH(PININT_INDEX));
   Chip_PININT_ClearIntStatus(LPC_GPIO_PIN_INT, 0);
   WriteStringWithInterrupt("Inside SW1 GPIO Interrupt Handler\n");
}


int main(void)
{
   SystemCoreClockUpdate();

   /* Initialize GPIO */
   Chip_GPIO_Init(LPC_GPIO);

   /* Initialize PININT driver */
   Chip_PININT_Init(LPC_GPIO_PIN_INT);

   /* Set pin back to GPIO (on some boards may have been changed to something
   else by Board_Init()) */
   Chip_IOCON_PinMuxSet(LPC_IOCON, TEST_INPUT_PIN_PORT, TEST_INPUT_PIN_BIT,
   (IOCON_DIGMODE_EN | IOCON_MODE_INACT) );

   /* Configure GPIO pin as input */
   Chip_GPIO_SetPinDIRInput(LPC_GPIO, TEST_INPUT_PORT, TEST_INPUT_PIN);

   /* Configure interrupt channel for the GPIO pin in INMUX block */
   Chip_INMUX_PinIntSel(PININT_INDEX, TEST_INPUT_PORT, TEST_INPUT_PIN);

   /* Configure channel interrupt as edge sensitive and falling edge interrupt */
   Chip_PININT_ClearIntStatus(LPC_GPIO_PIN_INT, /*PININTCH(PININT_INDEX)*/0);
   Chip_PININT_SetPinModeEdge(LPC_GPIO_PIN_INT, /*PININTCH(PININT_INDEX)*/0);
   Chip_PININT_EnableIntLow(LPC_GPIO_PIN_INT, /*PININTCH(PININT_INDEX)*/0);

   /* Enable interrupt in the NVIC */
   NVIC_ClearPendingIRQ(PININT_NVIC_NAME);
   NVIC_EnableIRQ(PININT_NVIC_NAME);

   /* Spin in a loop here. All the work is done in ISR. */
   while (1) {}

   return 0;
}

Even if I set the interrupt priority NVIC_SetPriority(PIN_INT0_IRQn, int_prio); it don't get an interrupt on press-releasing SW1 button.

0 Kudos

477 Views
soledad
NXP Employee
NXP Employee

Hello Shantanu,

I cannot find where you enable the pin clock (Chip_Clock_EnablePeriphClock). Did you set the clock??


Have a great day,
Sol

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

477 Views
shantanudhar
Contributor III

@soledad any help on this ?

0 Kudos

477 Views
shantanudhar
Contributor III

Sorry, I forgot to mention in the post that I have already powered the GPIO port using Chip_GPIO_Init(LPC_GPIO); at the very first line.

The problem still remains. Any idea ?

0 Kudos