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?

734 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

698 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

714 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

698 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

646 Views
Trups_123
Contributor I

waiting for solution

0 Kudos
Reply

625 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
%3CLINGO-SUB%20id%3D%22lingo-sub-2155253%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3EWhy%20is%20PIO1_8%20not%20working%20for%20external%20interrupt%20input%20on%20LPC1519%3F%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2155253%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CP%3EI%20am%20working%20with%20the%20LPC1519%20(ARM%20Cortex-M3)%20and%20trying%20to%20use%20Port%201%2C%20Pin%208%20(PIO1_8)%20as%20an%20external%20interrupt%20input%20for%20a%20water%20flow%20sensor.%3C%2FP%3E%3CP%3EI%20configured%20PIO1_8%20as%20a%20GPIO%20input%20and%20routed%20it%20to%20a%20PININT%20channel%20using%20the%20INMUX%2C%20then%20enabled%20falling-edge%20detection%20and%20enabled%20the%20IRQ.%20However%2C%20the%20interrupt%20never%20triggers%20when%20pulses%20are%20applied%20to%20P1_8.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2160884%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%20translate%3D%22no%22%3ERe%3A%20Why%20is%20PIO1_8%20not%20working%20for%20external%20interrupt%20input%20on%20LPC1519%3F%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2160884%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CP%3EHi%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Fcommunity.nxp.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F222924%22%20target%3D%22_blank%22%3E%40Trups_123%3C%2FA%3E%2C%3C%2FP%3E%0A%3CP%3EI%20apologize%20for%20taking%20a%20while%20to%20get%20back%20to%20you.%3C%2FP%3E%0A%3CP%3EI%20wasn't%20able%20to%20follow%20the%20entire%20configuration%20because%20I%20couldn't%20find%20the%20definition%20for%20LPC_GPIO_PORT.%20However%2C%20I%20recommend%20checking%20the%20periph_pinint%20example%2C%20which%20configures%20a%20pin%20interrupt%20triggered%20by%20a%20falling%20edge.%3C%2FP%3E%0A%3CP%3EYou%20can%20find%20this%20example%20in%20MCUXpresso%20by%20following%20these%20steps%3A%3C%2FP%3E%0A%3CP%3EQuickstart%20Panel%20-%26gt%3B%20Create%20or%20import%20project%20-%26gt%3B%20Import%20project(s)%20from%20file%20system.%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22Pablo_Ramos_0-1756503468961.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3Cspan%20class%3D%22lia-inline-image-display-wrapper%22%20image-alt%3D%22Pablo_Ramos_0-1756503468961.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3Cimg%20src%3D%22https%3A%2F%2Fcommunity.nxp.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F354860i5A21DDBF6DDDB632%2Fimage-size%2Fmedium%3Fv%3Dv2%26amp%3Bpx%3D400%22%20role%3D%22button%22%20title%3D%22Pablo_Ramos_0-1756503468961.png%22%20alt%3D%22Pablo_Ramos_0-1756503468961.png%22%20%2F%3E%3C%2Fspan%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3EProject%20archive%20(zip)%20-%26gt%3B%20Browse%20-%26gt%3B%20LPCOpen%20-%26gt%3B%20lpcxpresso_1549%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22Pablo_Ramos_1-1756503511164.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3Cspan%20class%3D%22lia-inline-image-display-wrapper%22%20image-alt%3D%22Pablo_Ramos_1-1756503511164.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3Cimg%20src%3D%22https%3A%2F%2Fcommunity.nxp.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F354861i02562A5186CE9457%2Fimage-size%2Fmedium%3Fv%3Dv2%26amp%3Bpx%3D400%22%20role%3D%22button%22%20title%3D%22Pablo_Ramos_1-1756503511164.png%22%20alt%3D%22Pablo_Ramos_1-1756503511164.png%22%20%2F%3E%3C%2Fspan%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3ESelect%20lpc_board_nxp_lpcxpresso_1549%2C%20lpc_chip_15xx%20and%20periph_pint%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22Pablo_Ramos_2-1756503530328.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3Cspan%20class%3D%22lia-inline-image-display-wrapper%22%20image-alt%3D%22Pablo_Ramos_2-1756503530328.png%22%20style%3D%22width%3A%20257px%3B%22%3E%3Cimg%20src%3D%22https%3A%2F%2Fcommunity.nxp.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F354862i966DFF200D5F074A%2Fimage-size%2Fmedium%3Fv%3Dv2%26amp%3Bpx%3D400%22%20role%3D%22button%22%20title%3D%22Pablo_Ramos_2-1756503530328.png%22%20alt%3D%22Pablo_Ramos_2-1756503530328.png%22%20%2F%3E%3C%2Fspan%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3EBest%20Regards%2C%3CBR%20%2F%3EPablo%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2159927%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%20translate%3D%22no%22%3ERe%3A%20Why%20is%20PIO1_8%20not%20working%20for%20external%20interrupt%20input%20on%20LPC1519%3F%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2159927%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CP%3Ewaiting%20for%20solution%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2155765%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%20translate%3D%22no%22%3ERe%3A%20Why%20is%20PIO1_8%20not%20working%20for%20external%20interrupt%20input%20on%20LPC1519%3F%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2155765%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CP%3E%23include%20%22chip.h%22%3CBR%20%2F%3E%23include%20%3CSTDIO.H%3E%3C%2FSTDIO.H%3E%3C%2FP%3E%3CP%3E%23define%20FLOW_PIN_PORT%201%3CBR%20%2F%3E%23define%20FLOW_PIN_NUM%208%3CBR%20%2F%3E%23define%20FLOW_IRQ_NUM%20PIN_INT0_IRQn%20%2F%2F%20Using%20PININT0%3CBR%20%2F%3E%23define%20FLOW_CH%20PININTCH0%3C%2FP%3E%3CP%3Evolatile%20uint32_t%20pulse_count%20%3D%200%3B%3C%2FP%3E%3CP%3E%2F*%20Interrupt%20Service%20Routine%20for%20flow%20sensor%20*%2F%3CBR%20%2F%3Evoid%20PIN_INT0_IRQHandler(void)%20%7B%3CBR%20%2F%3Eif%20(Chip_PININT_GetFallStates(LPC_PININT)%20%26amp%3B%20(1%20%26lt%3B%26lt%3B%20FLOW_CH))%20%7B%3CBR%20%2F%3Epulse_count%2B%2B%3B%20%2F%2F%20Count%20pulses%3CBR%20%2F%3EChip_PININT_ClearIntStatus(LPC_PININT%2C%20FLOW_CH)%3B%3CBR%20%2F%3E%7D%3CBR%20%2F%3E%7D%3C%2FP%3E%3CP%3Eint%20main(void)%20%7B%3CBR%20%2F%3ESystemCoreClockUpdate()%3B%3C%2FP%3E%3CP%3E%2F%2F%20Initialize%20GPIO%3CBR%20%2F%3EChip_GPIO_Init(LPC_GPIO_PORT)%3B%3CBR%20%2F%3EChip_IOCON_PinMuxSet(LPC_IOCON%2C%20FLOW_PIN_PORT%2C%20FLOW_PIN_NUM%2C%3CBR%20%2F%3E(IOCON_FUNC0%20%7C%20IOCON_MODE_PULLUP))%3B%3CBR%20%2F%3EChip_GPIO_SetPinDIRInput(LPC_GPIO_PORT%2C%20FLOW_PIN_PORT%2C%20FLOW_PIN_NUM)%3B%3C%2FP%3E%3CP%3E%2F%2F%20Map%20pin%20to%20interrupt%20channel%20(channel%200)%3CBR%20%2F%3EChip_INMUX_PinIntSel(0%2C%20FLOW_PIN_PORT%2C%20FLOW_PIN_NUM)%3B%3C%2FP%3E%3CP%3E%2F%2F%20Configure%20falling-edge%20interrupt%3CBR%20%2F%3EChip_PININT_ClearIntStatus(LPC_PININT%2C%20FLOW_CH)%3B%3CBR%20%2F%3EChip_PININT_SetPinModeEdge(LPC_PININT%2C%20FLOW_CH)%3B%3CBR%20%2F%3EChip_PININT_EnableIntLow(LPC_PININT%2C%20FLOW_CH)%3B%3C%2FP%3E%3CP%3E%2F%2F%20Enable%20NVIC%20for%20PIN_INT0%3CBR%20%2F%3ENVIC_ClearPendingIRQ(FLOW_IRQ_NUM)%3B%3CBR%20%2F%3ENVIC_EnableIRQ(FLOW_IRQ_NUM)%3B%3C%2FP%3E%3CP%3Ewhile%20(1)%20%7B%3CBR%20%2F%3Euint32_t%20start_count%20%3D%20pulse_count%3B%3C%2FP%3E%3CP%3E%2F%2F%20crude%201%20second%20delay%20loop%3CBR%20%2F%3Efor%20(volatile%20uint32_t%20i%20%3D%200%3B%20i%20%26lt%3B%20(SystemCoreClock%2F1000%20*%201000)%3B%20i%2B%2B)%3B%3C%2FP%3E%3CP%3Euint32_t%20pulses_per_sec%20%3D%20pulse_count%20-%20start_count%3B%3CBR%20%2F%3Efloat%20flow_rate%20%3D%20(float)pulses_per_sec%20%2F%207.5f%3B%20%2F%2F%20L%2Fmin%20(depends%20on%20sensor%20spec!)%3C%2FP%3E%3CP%3Eprintf(%22Flow%20Rate%3A%20%25.2f%20L%2Fmin%2C%20Total%20pulses%3A%20%25lu%5Cn%22%2C%3CBR%20%2F%3Eflow_rate%2C%20pulse_count)%3B%3CBR%20%2F%3E%7D%3CBR%20%2F%3E%7D%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2155762%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%20translate%3D%22no%22%3ERe%3A%20Why%20is%20PIO1_8%20not%20working%20for%20external%20interrupt%20input%20on%20LPC1519%3F%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2155762%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%23define%20FLOW_PIN_PORT%201%3CBR%20%2F%3E%23define%20FLOW_PIN_NUM%208%3CBR%20%2F%3E%23define%20FLOW_IRQ_NUM%20PIN_INT0_IRQn%20%2F%2F%20Example%3A%20use%20PIN_INT0%3CBR%20%2F%3E%23define%20FLOW_CH%20PININTCH0%3CBR%20%2F%3E%3CBR%20%2F%3Evolatile%20uint32_t%20pulse_count%20%3D%200%3B%3CBR%20%2F%3E%3CBR%20%2F%3E%2F*%20Interrupt%20Service%20Routine%20for%20flow%20sensor%20*%2F%3CBR%20%2F%3Evoid%20PIN_INT0_IRQHandler(void)%20%7B%3CBR%20%2F%3Epulse_count%2B%2B%3B%20%2F%2F%20Count%20pulses%3CBR%20%2F%3EChip_PININT_ClearFallStates(LPC_PININT%2C%20FLOW_CH)%3B%3CBR%20%2F%3E%7D%3CBR%20%2F%3E%3CBR%20%2F%3Eint%20main(void)%20%7B%3CBR%20%2F%3ESystemCoreClockUpdate()%3B%3CBR%20%2F%3E%3CBR%20%2F%3E%2F%2F%20Initialize%20GPIO%3CBR%20%2F%3EChip_GPIO_Init(LPC_GPIO_PORT)%3B%3CBR%20%2F%3EChip_IOCON_PinMuxSet(LPC_IOCON%2C%20FLOW_PIN_PORT%2C%20FLOW_PIN_NUM%2C%3CBR%20%2F%3E(IOCON_FUNC0%20%7C%20IOCON_MODE_PULLUP))%3B%3CBR%20%2F%3EChip_GPIO_SetPinDIRInput(LPC_GPIO_PORT%2C%20FLOW_PIN_PORT%2C%20FLOW_PIN_NUM)%3B%3CBR%20%2F%3E%3CBR%20%2F%3E%2F%2F%20Map%20pin%20to%20interrupt%20channel%3CBR%20%2F%3EChip_INMUX_PinIntSel(0%2C%20FLOW_PIN_PORT%2C%20FLOW_PIN_NUM)%3B%3CBR%20%2F%3E%3CBR%20%2F%3E%2F%2F%20Configure%20falling-edge%20interrupt%3CBR%20%2F%3EChip_PININT_ClearIntStatus(LPC_PININT%2C%20FLOW_CH)%3B%3CBR%20%2F%3EChip_PININT_SetPinModeEdge(LPC_PININT%2C%20FLOW_CH)%3B%3CBR%20%2F%3EChip_PININT_EnableIntLow(LPC_PININT%2C%20FLOW_CH)%3B%3CBR%20%2F%3E%3CBR%20%2F%3E%2F%2F%20Enable%20NVIC%3CBR%20%2F%3ENVIC_ClearPendingIRQ(FLOW_IRQ_NUM)%3B%3CBR%20%2F%3ENVIC_EnableIRQ(FLOW_IRQ_NUM)%3B%3CBR%20%2F%3E%3CBR%20%2F%3Ewhile(1)%20%7B%3CBR%20%2F%3E%2F%2F%20Example%3A%20measure%20flow%20every%201%20second%3CBR%20%2F%3Euint32_t%20start_count%20%3D%20pulse_count%3B%3CBR%20%2F%3EChip_Clock_System_BusyWait_ms(1000)%3B%3CBR%20%2F%3Euint32_t%20pulses_per_sec%20%3D%20pulse_count%20-%20start_count%3B%3CBR%20%2F%3E%3CBR%20%2F%3Efloat%20flow_rate%20%3D%20(float)pulses_per_sec%20%2F%207.5f%3B%20%2F%2F%20L%2Fmin%3CBR%20%2F%3Eprintf(%22Flow%20Rate%3A%20%25.2f%20L%2Fmin%2C%20Total%20pulses%3A%20%25lu%5Cn%22%2C%20flow_rate%2C%20pulse_count)%3B%3CBR%20%2F%3E%7D%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2155440%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%20translate%3D%22no%22%3ERe%3A%20Why%20is%20PIO1_8%20not%20working%20for%20external%20interrupt%20input%20on%20LPC1519%3F%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2155440%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CP%3EHi%20%3CA%20href%3D%22https%3A%2F%2Fcommunity.nxp.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F222924%22%20target%3D%22_blank%22%3E%40Trups_123%3C%2FA%3E%2C%3C%2FP%3E%0A%3CP%3EHow%20are%20you%20generating%20the%20pulses%20that%20are%20applied%20to%20P1_8%3F%3C%2FP%3E%0A%3CP%3EAlso%2C%20could%20you%20please%20share%20a%20snippet%20of%20your%20code%20where%20you%20set%20up%20pin%20P1_8%20as%20an%20external%20interrupt%3F%3C%2FP%3E%0A%3CP%3EBest%20Regards%2C%3CBR%20%2F%3EPablo%3C%2FP%3E%3C%2FLINGO-BODY%3E