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.

How to setup GPIO_P4 and GPIO_P5 Interrupt?

I am using TM4C129X and CCS6.1. The main code is listed below. The result is not ok, it can't run into interrupt handler.

int main(void)

{

...

    Init_interrupt();
    HWREG(NVIC_SW_TRIG) = INT_GPIOP4 - 16;

}

void PortPIntHandler()
{
 LED2_ON;
}

void Init_interrupt()
{

     SysCtlPeripheralEnable(SYSCTL_PERIPH_EPI0);

    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOP);

 GPIOIntRegister(GPIO_PORTP_BASE, PortPIntHandler);
 GPIOPinTypeGPIOInput(GPIO_PORTP_BASE, GPIO_PIN_4 | GPIO_PIN_5);
 GPIOIntTypeSet(GPIO_PORTA_BASE, GPIO_PIN_4 | GPIO_PIN_5, GPIO_RISING_EDGE);

 GPIOIntEnable(GPIO_PORTA_BASE, GPIO_PIN_4 | GPIO_PIN_5);

 IntMasterEnable();
}

  • Hello Jian,

    1. Check that the code execution is not in Fault Handler
    2. The IntEnable(INT_GPIOP) is also missing which allows the NVIC to see the interrupt for Port P.
    3, Why is PORTA Base being used for PORTP???

    Regards
    Amit
  • Hello Amit,

           Thanks for your answer.

           Does it need to clear interrupt pending bit in interrupt function? 

    Regards.

    Li Jian Ri

  • Hello Li,

    Absolutely. otherwise the interrupt handler will keep on exiting and then re-entering even if the pin state does not change,.

    Regards
    Amit
  • Hello Amit,

          How to clear the Pending bit of interrupt GPIO_P4 and GPIO_P5? Thanks!

    Regards
    Li Jian Ri

     

  • Hello Jian

    Please go through the documentation on TivaWare API's. That would clearly describe the functions of the API's w.r.t configuration and servcing of interrupts

    Regards
    Amit
  • Hello Amit,

         I have found Interrupt Controller (NVIC) APIs in TivaWare™ Peripheral Driver Library USER’S GUIDE before,  The APIs are listed below. I have try the function IntPendClear(INT_GPIOP4), but it is no use.  Thanks for your help!

    void IntDisable (uint32_t ui32Interrupt)
    void IntEnable (uint32_t ui32Interrupt)
    uint32_t IntIsEnabled (uint32_t ui32Interrupt)
    bool IntMasterDisable (void)
    bool IntMasterEnable (void)
    void IntPendClear (uint32_t ui32Interrupt)
    void IntPendSet (uint32_t ui32Interrupt)
    int32_t IntPriorityGet (uint32_t ui32Interrupt)
    uint32_t IntPriorityGroupingGet (void)
    void IntPriorityGroupingSet (uint32_t ui32Bits)
    uint32_t IntPriorityMaskGet (void)
    void IntPriorityMaskSet (uint32_t ui32PriorityMask)
    void IntPrioritySet (uint32_t ui32Interrupt, uint8_t ui8Priority)
    void IntRegister (uint32_t ui32Interrupt, void (pfnHandler)(void))
    void IntTrigger (uint32_t ui32Interrupt)
    void IntUnregister (uint32_t ui32Interrupt)

    Regards

    Li Jian Ri

  • Hello Amit,

          I have found Interrupt 0-31 Clear Pending (UNPEND0), offset 0x280 in datasheet, should I use this register to clear the pending bit?

    Regards

    Li Jian Ri

  • Hello Amit
            I have wrote  HWREG(NVIC_UNPEND2) = NVIC_UNPEND2_INT_M; and IntPendClear(INT_GPIOP4); in my interrupt handler, it is no use.  the interrupt handler keep on exiting. Can you help me ? Thanks!


    Regards
    Li Jian Ri

  • Hello Jian,

    You have to clear the interrupt source at the source, and the source is the GPIO. So you need to look into the GPIO API's for the corrective action.

    Regards
    Amit
  • Hello Amit,

             Thanks for your answer. It is ok!

             I have another question, I want to set up GPIO_P4 and GPIO_P5 interrupt handler in TI RTOS. I have setup GPIO_J port    interrupt  successfully. Some code is below:

    const GPIO_Callbacks EK_TM4C1294XL_gpioPortJCallbacks = {
        GPIO_PORTJ_BASE, INT_GPIOJ, &callbackPortJHwi,
        {gpioButtonFxn0, gpioButtonFxn1, NULL, NULL, NULL, NULL, NULL, NULL}
    };

         But if I change INT_GPIOJ to INT_GPIOP ,  it can't be compiled succesfully. Can you tell I should how to write? Thanks!


    Regards
    Li Jian Ri

     

  • Hello Li

    GPIO P has its interrupt vector defined as P0, P1 and so on till P7.

    Regards
    Amit