I am using LPC824 board and want to read tacho signals from one of the pins.I have problems with enabling the right interrupts and clearing the flags. Could you help me
#include "fsl_debug_console.h"
#include "pin_mux.h"
#include "board.h"
#include "fsl_gpio.h"
#include <stdbool.h>
#include <stdio.h>
/*******************************************************************************
* Definitions
******************************************************************************/
#define BOARD_LED_PORT 0U
#define BOARD_LED_PIN 12U
#define TACHO_PIN 17U
volatile uint32_t captureCounter = 0;
volatile bool captureEnabled = true;
/*******************************************************************************
* Code
******************************************************************************/
void GPIO_IRQHandler(void)
{
// Check if the interrupt is caused by TACHO_PIN rising edge
if (GPIO_PinRead(GPIO, 0, TACHO_PIN))
{
captureCounter++;
// Clear the interrupt flag
//GPIO_PortClearInterruptFlags(GPIO, 0, 1U << TACHO_PIN);
}
}
void delay(uint32_t ms)
{
uint32_t ticks = ms * (SystemCoreClock / 1000U);
while (ticks--)
{
__asm("nop");
}
}
int main(void)
{
/* Init board hardware */
BOARD_InitBootPins();
BOARD_InitBootClocks();
BOARD_InitDebugConsole();
/* Configure TACHO_PIN as an input with interrupt on rising edge */
gpio_pin_config_t pinConfig = {
kGPIO_DigitalInput,
0,
};
GPIO_PinInit(GPIO, 0, TACHO_PIN, &pinConfig);
// Enable the GPIO interrupt
NVIC_EnableIRQ(PIN_INT0_IRQn);
while (1)
{
// Capture for approximately 1 second
delay(1000000U);
// Disable GPIO interrupt
NVIC_DisableIRQ(PIN_INT0_IRQn);
// Print the frequency over the last second
PRINTF("\r\nFrequency (last second): %u Hz\r\n", captureCounter);
// Reset the capture counter for the next measurement
captureCounter = 0;
// Enable GPIO interrupt for the next measurement
NVIC_EnableIRQ(PIN_INT0_IRQn);
}
}
@nxp