LPC4330 GPIO Pin Interrupt

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

LPC4330 GPIO Pin Interrupt

Jump to solution
1,953 Views
C-Coder
Contributor III

We're using an LPC4330FET180 and I want to get a GPIO interrupt on pin D4. D4 maps to P4_0 or GPIO2[0] in the user's manual. Assuming the electrical side of things is correct, I'm questioning my software setup code. We have the pin brought out to a debug pin that I can watch with the scope. The scope is showing an interrupt when I expect one, but I'm never hitting the handler in the software. I pretty much cut/paste the code from periph_pinint and have this:

#define INT_PORT 2
#define INT_PIN 0
 Chip_SCU_PinMuxSet(INT_PORT, INT_PIN, (SCU_MODE_INBUFF_EN | SCU_MODE_PULLUP | SCU_MODE_FUNC0));
 Chip_GPIO_SetPinDIROutput(LPC_GPIO_PORT, INT_PORT, INT_PIN); // Output
 Chip_SCU_GPIOIntPinSel(0, INT_PORT, INT_PIN);

 Chip_PININT_ClearIntStatus(LPC_GPIO_PIN_INT, PININTCH(0));
 Chip_PININT_SetPinModeEdge(LPC_GPIO_PIN_INT, PININTCH(0));
 Chip_PININT_EnableIntHigh(LPC_GPIO_PIN_INT, PININTCH(0));

 NVIC_ClearPendingIRQ(PIN_INT0_IRQn);
 NVIC_EnableIRQ(PIN_INT0_IRQn);

Am I missing something?

Thanks,

Torin

Labels (3)
0 Kudos
Reply
1 Solution
1,773 Views
C-Coder
Contributor III

I ended up figuring out what the problem was - schematic was mislabeled. But for those that are curious how to do it, here's how I did it for pin PB_2:

#define CPU_PORT 11
#define CPU_PORT_PIN 0
#define GPIO_PORT 5
#define GPIO_PIN 22

// Setup CPU port 11, pin 0, with an input buffer, pull down resistor, and function 4 mode.
Chip_SCU_PinMuxSet(CPU_PORT, CPU_PORT_PIN, (SCU_MODE_INBUFF_EN | SCU_MODE_PULLDOWN | SCU_MODE_FUNC4));

// Set GPIO port 5, pin 22, as an input
Chip_GPIO_SetPinDIRInput(LPC_GPIO_PORT, GPIO_PORT, GPIO_PIN);

// Set GPIO port 5, pin 22, as an pin for CPU pin interrupt port 0
Chip_SCU_GPIOIntPinSel(0, GPIO_PORT, GPIO_PIN);

// Clear any pending interrupts on CPU pin interrupt port 0
Chip_PININT_ClearIntStatus(LPC_GPIO_PIN_INT, PININTCH0);

// Set CPU pin interrupt port 0 as edge sensitive
Chip_PININT_SetPinModeEdge(LPC_GPIO_PIN_INT, PININTCH0);

// Set CPU pin interrupt port 0 as high enabled
Chip_PININT_EnableIntHigh(LPC_GPIO_PIN_INT, PININTCH0);

// Clear any pending interrupts in the NVIC for CPU pin interrupts on port 0
NVIC_ClearPendingIRQ(PIN_INT0_IRQn);

// Enable the interrupts in the NVIC for CPU pin interrupts on port 0
NVIC_EnableIRQ(PIN_INT0_IRQn);

Torin

View solution in original post

0 Kudos
Reply
4 Replies
1,773 Views
Sabina_Bruce
NXP Employee
NXP Employee

Glad you were able to resolve thi quickly. Also, thank you for providing the answer!

Best Regards,

Sabina

0 Kudos
Reply
1,774 Views
C-Coder
Contributor III

I ended up figuring out what the problem was - schematic was mislabeled. But for those that are curious how to do it, here's how I did it for pin PB_2:

#define CPU_PORT 11
#define CPU_PORT_PIN 0
#define GPIO_PORT 5
#define GPIO_PIN 22

// Setup CPU port 11, pin 0, with an input buffer, pull down resistor, and function 4 mode.
Chip_SCU_PinMuxSet(CPU_PORT, CPU_PORT_PIN, (SCU_MODE_INBUFF_EN | SCU_MODE_PULLDOWN | SCU_MODE_FUNC4));

// Set GPIO port 5, pin 22, as an input
Chip_GPIO_SetPinDIRInput(LPC_GPIO_PORT, GPIO_PORT, GPIO_PIN);

// Set GPIO port 5, pin 22, as an pin for CPU pin interrupt port 0
Chip_SCU_GPIOIntPinSel(0, GPIO_PORT, GPIO_PIN);

// Clear any pending interrupts on CPU pin interrupt port 0
Chip_PININT_ClearIntStatus(LPC_GPIO_PIN_INT, PININTCH0);

// Set CPU pin interrupt port 0 as edge sensitive
Chip_PININT_SetPinModeEdge(LPC_GPIO_PIN_INT, PININTCH0);

// Set CPU pin interrupt port 0 as high enabled
Chip_PININT_EnableIntHigh(LPC_GPIO_PIN_INT, PININTCH0);

// Clear any pending interrupts in the NVIC for CPU pin interrupts on port 0
NVIC_ClearPendingIRQ(PIN_INT0_IRQn);

// Enable the interrupts in the NVIC for CPU pin interrupts on port 0
NVIC_EnableIRQ(PIN_INT0_IRQn);

Torin

0 Kudos
Reply
1,773 Views
C-Coder
Contributor III

I did also notice that I needed to change

Chip_GPIO_SetPinDIROutput(LPC_GPIO_PORT, INT_PORT, INT_PIN); // Output

to

Chip_GPIO_SetPinDIRInput(LPC_GPIO_PORT, INT_PORT, INT_PIN);

But am still not getting hitting the handler.

Thanks,

Torin

0 Kudos
Reply
1,773 Views
C-Coder
Contributor III

Debugging through the code some more and looking at memory values, it would appear that to use P4_0, I really want the following:

#define INT_PORT 4

 rather than

#define INT_PORT 2

Unfortunately, even after changing that, I still don't hit a break point in the handler.

Anyone have any ideas?

Thanks,

Torin

0 Kudos
Reply