Why is PIO1_8 not working for external interrupt input on LPC1519?

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

Why is PIO1_8 not working for external interrupt input on LPC1519?

1,533 Views
Trups_123
Contributor I

I am working with the LPC1519 (ARM Cortex-M3) and trying to use Port 1, Pin 8 (PIO1_8) as an external interrupt input for a water flow sensor.

I configured PIO1_8 as a GPIO input and routed it to a PININT channel using the INMUX, then enabled falling-edge detection and enabled the IRQ. However, the interrupt never triggers when pulses are applied to P1_8.

0 Kudos
Reply
5 Replies

1,497 Views
Trups_123
Contributor I

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

#define FLOW_PIN_PORT 1
#define FLOW_PIN_NUM 8
#define FLOW_IRQ_NUM PIN_INT0_IRQn // Using PININT0
#define FLOW_CH PININTCH0

volatile uint32_t pulse_count = 0;

/* Interrupt Service Routine for flow sensor */
void PIN_INT0_IRQHandler(void) {
if (Chip_PININT_GetFallStates(LPC_PININT) & (1 << FLOW_CH)) {
pulse_count++; // Count pulses
Chip_PININT_ClearIntStatus(LPC_PININT, FLOW_CH);
}
}

int main(void) {
SystemCoreClockUpdate();

// Initialize GPIO
Chip_GPIO_Init(LPC_GPIO_PORT);
Chip_IOCON_PinMuxSet(LPC_IOCON, FLOW_PIN_PORT, FLOW_PIN_NUM,
(IOCON_FUNC0 | IOCON_MODE_PULLUP));
Chip_GPIO_SetPinDIRInput(LPC_GPIO_PORT, FLOW_PIN_PORT, FLOW_PIN_NUM);

// Map pin to interrupt channel (channel 0)
Chip_INMUX_PinIntSel(0, FLOW_PIN_PORT, FLOW_PIN_NUM);

// Configure falling-edge interrupt
Chip_PININT_ClearIntStatus(LPC_PININT, FLOW_CH);
Chip_PININT_SetPinModeEdge(LPC_PININT, FLOW_CH);
Chip_PININT_EnableIntLow(LPC_PININT, FLOW_CH);

// Enable NVIC for PIN_INT0
NVIC_ClearPendingIRQ(FLOW_IRQ_NUM);
NVIC_EnableIRQ(FLOW_IRQ_NUM);

while (1) {
uint32_t start_count = pulse_count;

// crude 1 second delay loop
for (volatile uint32_t i = 0; i < (SystemCoreClock/1000 * 1000); i++);

uint32_t pulses_per_sec = pulse_count - start_count;
float flow_rate = (float)pulses_per_sec / 7.5f; // L/min (depends on sensor spec!)

printf("Flow Rate: %.2f L/min, Total pulses: %lu\n",
flow_rate, pulse_count);
}
}

0 Kudos
Reply

1,513 Views
Pablo_Ramos
NXP Employee
NXP Employee

Hi @Trups_123,

How are you generating the pulses that are applied to P1_8?

Also, could you please share a snippet of your code where you set up pin P1_8 as an external interrupt?

Best Regards,
Pablo

0 Kudos
Reply

1,497 Views
Trups_123
Contributor I
#define FLOW_PIN_PORT 1
#define FLOW_PIN_NUM 8
#define FLOW_IRQ_NUM PIN_INT0_IRQn // Example: use PIN_INT0
#define FLOW_CH PININTCH0

volatile uint32_t pulse_count = 0;

/* Interrupt Service Routine for flow sensor */
void PIN_INT0_IRQHandler(void) {
pulse_count++; // Count pulses
Chip_PININT_ClearFallStates(LPC_PININT, FLOW_CH);
}

int main(void) {
SystemCoreClockUpdate();

// Initialize GPIO
Chip_GPIO_Init(LPC_GPIO_PORT);
Chip_IOCON_PinMuxSet(LPC_IOCON, FLOW_PIN_PORT, FLOW_PIN_NUM,
(IOCON_FUNC0 | IOCON_MODE_PULLUP));
Chip_GPIO_SetPinDIRInput(LPC_GPIO_PORT, FLOW_PIN_PORT, FLOW_PIN_NUM);

// Map pin to interrupt channel
Chip_INMUX_PinIntSel(0, FLOW_PIN_PORT, FLOW_PIN_NUM);

// Configure falling-edge interrupt
Chip_PININT_ClearIntStatus(LPC_PININT, FLOW_CH);
Chip_PININT_SetPinModeEdge(LPC_PININT, FLOW_CH);
Chip_PININT_EnableIntLow(LPC_PININT, FLOW_CH);

// Enable NVIC
NVIC_ClearPendingIRQ(FLOW_IRQ_NUM);
NVIC_EnableIRQ(FLOW_IRQ_NUM);

while(1) {
// Example: measure flow every 1 second
uint32_t start_count = pulse_count;
Chip_Clock_System_BusyWait_ms(1000);
uint32_t pulses_per_sec = pulse_count - start_count;

float flow_rate = (float)pulses_per_sec / 7.5f; // L/min
printf("Flow Rate: %.2f L/min, Total pulses: %lu\n", flow_rate, pulse_count);
}
0 Kudos
Reply

1,445 Views
Trups_123
Contributor I

waiting for solution

0 Kudos
Reply

1,424 Views
Pablo_Ramos
NXP Employee
NXP Employee

Hi @Trups_123,

I apologize for taking a while to get back to you.

I wasn't able to follow the entire configuration because I couldn't find the definition for LPC_GPIO_PORT. However, I recommend checking the periph_pinint example, which configures a pin interrupt triggered by a falling edge.

You can find this example in MCUXpresso by following these steps:

Quickstart Panel -> Create or import project -> Import project(s) from file system.

Pablo_Ramos_0-1756503468961.png

Project archive (zip) -> Browse -> LPCOpen -> lpcxpresso_1549

Pablo_Ramos_1-1756503511164.png

Select lpc_board_nxp_lpcxpresso_1549, lpc_chip_15xx and periph_pint

Pablo_Ramos_2-1756503530328.png

Best Regards,
Pablo

0 Kudos
Reply