Other Parts Discussed in Thread: EK-TM4C123GXL,
I am writing a simple code that works as follows:
press SW1
when SW1 is released a falling edge is detected and the ISR corresponding to the pin PF4 is executed and an LED is turned on.
similarly it happens when SW2 is pressed.
I am not able to configure the interrupt properly.
in the user guide there are APIs for peripheral specific interrupts and NVIC interrupts, how to know which one to use?
Please guide me regarding the same.
I am posting my code for reference.
#include<stdint.h>
#include<stdbool.h>
#include<hw_memmap.h>
#include<gpio.h>
#include<interrupt.h>
#include<sysctl.h>
#define GPIOCR (*(unsigned long *)0x40025524)
#define GPIOLOCK (*(unsigned long *)0x40025520)
void gpio_Interrupt_Init(void);
void SW1isr(void);
void SW2isr(void);
int main(void)
{
gpio_Interrupt_Init();
return 0;
}
void gpio_Interrupt_Init()
{
void (*SW1_int)(void);
void (*SW2_int)(void);
SW1_int = &SW1isr;
SW2_int = &SW2isr;
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);
GPIOLOCK =0x4C4F434B;
GPIOCR =0xFF;
GPIOIntRegisterPin(GPIO_PORTF_BASE,GPIO_PIN_4, SW1_int);
GPIOIntRegisterPin(GPIO_PORTF_BASE,GPIO_PIN_0, SW2_int);
GPIOPinTypeGPIOInput(GPIO_PORTF_BASE, (GPIO_PIN_0 | GPIO_PIN_4));
GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, (GPIO_PIN_2 | GPIO_PIN_3));
GPIOIntTypeSet(GPIO_PORTF_BASE, (GPIO_PIN_0 | GPIO_PIN_4), GPIO_FALLING_EDGE);
GPIOIntEnable(GPIO_PORTF_BASE, GPIO_PIN_0|GPIO_PIN_4);
}
void SW1isr()
{
GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_2, ~(uint8_t)GPIOPinRead(GPIO_PORTF_BASE, GPIO_PIN_2));
GPIOIntClear(GPIO_PORTF_BASE, GPIO_INT_PIN_4);
}
void SW2isr()
{
GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_3, ~(uint8_t)GPIOPinRead(GPIO_PORTF_BASE, GPIO_PIN_3));
GPIOIntClear(GPIO_PORTF_BASE, GPIO_INT_PIN_0);
}