This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Trying to enable interrupt for GPIO pin F0 .

Other Parts Discussed in Thread: TM4C123GH6PM

Hi,

I am trying to enable interrupt for Gpio pin F0 and want to send a command to GSM modem when SW2 is pressed.

But its not going into interrupt routine.

The code is given below:


#include <stdint.h>
#include <stdbool.h>
#include "inc/hw_types.h"
#include "inc/hw_memmap.h"
#include "driverlib/sysctl.h"
#include "driverlib/gpio.h"
#include "driverlib/i2c.h"
#include "driverlib/rom.h"
#include "driverlib/pin_map.h"
#include "inc/tm4c123gh6pm.h"
#include "inc/hw_i2c.h"
#include "driverlib/uart.h"
#include "driverlib/interrupt.h"

#define MEM 0xE0028000
int i =0;
int y=0;
int K=0;
int J =0;
uint8_t send1[14]={'A','T','+','C','S','C','S','=','"','G','S','M','"',0x0d};

uint8_t CMD1[7]={'A','T','+','C','S','Q',0x0d};

uint8_t call[15]={'A','T','D','9','8','0','4','8','1','8','9','1','1',';',0x0d};
uint8_t SMSArray[200];

void UartIntHandler(void)
{GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3,0x02);
//static uint32_t x = 0x00000000 ;
UARTIntClear(UART1_BASE,UART_INT_TX|UART_INT_RX);
SMSArray[y]= UARTCharGet(UART1_BASE);
UARTCharPut(UART0_BASE, SMSArray[y]);
y++;
if(SMSArray[80]=='O'&&SMSArray[81]=='N')
SendSms();
}

void GpioIntHandler(void)

{ GPIOIntClear(GPIO_PORTF_BASE, GPIO_PIN_0);
GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3,0x04);

//if(GPIOPinRead(GPIO_PORTF_BASE, GPIO_PIN_4)==0); //low level checking
for(K=0;K<=15;K++)
{
UARTCharPut(UART1_BASE, call[K]);
SysCtlDelay(20000000);
}
}

int main(void)
{
SysCtlClockSet(SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ);
SysCtlPeripheralEnable(SYSCTL_PERIPH_UART1);
SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOC);
GPIOPinConfigure(GPIO_PB0_U1RX);
GPIOPinConfigure(GPIO_PB1_U1TX);
GPIOPinTypeUART(GPIO_PORTB_BASE, GPIO_PIN_0|GPIO_PIN_1);
GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_2);
GPIOPinTypeGPIOInput(GPIO_PORTF_BASE, GPIO_PIN_0|GPIO_PIN_4);
GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0|GPIO_PIN_1);
UARTConfigSetExpClk(UART1_BASE, SysCtlClockGet(), 9600,(UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE | UART_CONFIG_PAR_NONE));
UARTConfigSetExpClk(UART0_BASE, SysCtlClockGet(), 9600,(UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE | UART_CONFIG_PAR_NONE));
IntEnable(INT_UART1);
GPIOPadConfigSet(GPIO_PORTF_BASE,GPIO_PIN_0,GPIO_STRENGTH_2MA,GPIO_PIN_TYPE_STD_WPU);
GPIOIntDisable(GPIO_PORTF_BASE, GPIO_PIN_0); // Disable interrupt for PF4 (in case it was enabled)
GPIOIntClear(GPIO_PORTF_BASE, GPIO_PIN_0); // Clear pending interrupts for PF4
GPIOIntRegister(GPIO_PORTF_BASE, GpioIntHandler); // Register our handler function for port F
GPIOIntTypeSet(GPIO_PORTF_BASE, GPIO_PIN_0,GPIO_FALLING_EDGE); // Configure PF4 for falling edge trigger
GPIOIntEnable(GPIO_PORTF_BASE, GPIO_PIN_0); // Enable interrupt for PF0
UARTIntEnable(UART1_BASE,UART_INT_TX|UART_INT_RX);
UARTEnable(UART1_BASE);
UARTEnable(UART0_BASE);
IntMasterEnable();
for(J=0;J<=7;J++)
{GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3,0x0E);

UARTCharPut(UART1_BASE, CMD1[J]);
SysCtlDelay(20000000);


while (1)

{

}
}

  • Hello Turjasu

    IntEnable(INT_GPIOF)

    is missing in the code which would allow the NVIC to register the interrupt from GPIO Port F.

    Regards

    Amit

  • Hi,

    First please correct your code - in several places you speek about PF4, still write GPIO_PIN_0 - if really need PF0,  then see the first thread about NMI processing - as default PF0 is NMI, and you need to unlock it first before using it as input.

    Search the forum how to do it, there are a great number of complaints about or see the the example qs-rgb. There you can find out how to solve another problem - debouncing a switch.

    Petrei

  • Hello Turjasu,

    Petrei's post is very much important and valid as PF0 is a locked pin (my oversight in not realizing the same). Are you unlocking the pin before using it as a GPIO?

    Regards

    Amit

  • Hi amit,

      Yes I understand what Petrei said. But we have done it using the PF4, as PF0 is locked. We were missing out on the IntEnable(INT_GPIOF). Thanks to you both. this is done