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.

Interrupt not working



In main :

    Button_IF_Init(ResetDeviceInterruptHandler, StandbyInterruptHandler, PresenceInterruptHandler);
    Button_IF_EnableInterrupt(SW3);
    Button_IF_EnableInterrupt(SW4);

Button_IF_EnableInterrupt(SW2);

//*****************************************************************************
// button_if.c
//
// CC3200 Launchpad button interface APIs
//
//*****************************************************************************

#include <stdlib.h>
#include "hw_types.h"
#include "hw_ints.h"
#include "rom.h"
#include "rom_map.h"
#include "gpio.h"
#include "interrupt.h"
#include "pin.h"
#include "hw_memmap.h"

#include "osi.h"

#include "button_interface.h"

P_INT_HANDLER g_S2InterruptHdl;
P_INT_HANDLER g_S3InterruptHdl;
P_INT_HANDLER g_S4InterruptHdl;

void GPIOs4IntHandler()
{

    unsigned long ulPinState =  GPIOIntStatus(GPIOA3_BASE,1);

    if(ulPinState & GPIO_PIN_4)
    {
        Button_IF_DisableInterrupt(SW4);
        g_S4InterruptHdl();
    }
}
//*****************************************************************************
//
//! GPIO Interrupt Handler for S3 button
//!
//! \param None
//!
//! \return None
//
//*****************************************************************************
void GPIOs3IntHandler()
{

    unsigned long ulPinState =  GPIOIntStatus(GPIOA1_BASE,1);

    if(ulPinState & GPIO_PIN_5)
    {
        Button_IF_DisableInterrupt(SW3);
        g_S3InterruptHdl();
    }
}
//*****************************************************************************
//
//! GPIO Interrupt Handler for S2 button
//!
//! \param None
//!
//! \return None
//
//*****************************************************************************
void GPIOs2IntHandler()
{
    unsigned long ulPinState =  GPIOIntStatus(GPIOA2_BASE,1);
    if(ulPinState & GPIO_PIN_6)
    {
        Button_IF_DisableInterrupt(SW2);
        g_S2InterruptHdl();
    }
}

//*****************************************************************************
//
//!  \brief Initialize Push Button GPIO
//!
//! \param[in] S2InterruptHdl          GPIO Interrupt Handler for SW2 LP button
//! \param[in] S3InterruptHdl          GPIO Interrupt Handler for SW3 LP button

//!
//! \return none
//!
//! \brief  Initializes Push Button Ports and Pins
//
//*****************************************************************************
void Button_IF_Init(P_INT_HANDLER S2InterruptHdl,P_INT_HANDLER S3InterruptHdl, P_INT_HANDLER S4InterruptHdl )
{
    if(S4InterruptHdl != NULL)
    {
        //
        // Set Interrupt Type for GPIO
        //
        MAP_GPIOIntTypeSet(GPIOA3_BASE,GPIO_PIN_4,GPIO_FALLING_EDGE);

        g_S4InterruptHdl = S4InterruptHdl;

        //
        // Register Interrupt handler
        //
        osi_InterruptRegister(INT_GPIOA3,(P_OSI_INTR_ENTRY)GPIOs4IntHandler, \
                                INT_PRIORITY_LVL_1);

        //
        // Enable Interrupt
        //
        MAP_GPIOIntClear(GPIOA3_BASE,GPIO_PIN_4);
        MAP_GPIOIntEnable(GPIOA3_BASE,GPIO_INT_PIN_4);
    }

    if(S3InterruptHdl != NULL)
    {
        //
        // Set Interrupt Type for GPIO
        //
        MAP_GPIOIntTypeSet(GPIOA1_BASE,GPIO_PIN_5,GPIO_FALLING_EDGE);

        g_S3InterruptHdl = S3InterruptHdl;

        //
        // Register Interrupt handler
        //
        osi_InterruptRegister(INT_GPIOA1,(P_OSI_INTR_ENTRY)GPIOs3IntHandler, \
                                INT_PRIORITY_LVL_1);
        //
        // Enable Interrupt
        //
        MAP_GPIOIntClear(GPIOA1_BASE,GPIO_PIN_5);
        MAP_GPIOIntEnable(GPIOA1_BASE,GPIO_INT_PIN_5);
    }

    if(S2InterruptHdl != NULL)
    {
        //
        // Set Interrupt Type for GPIO
        //
        MAP_GPIOIntTypeSet(GPIOA2_BASE,GPIO_PIN_6,GPIO_FALLING_EDGE);

        g_S2InterruptHdl = S2InterruptHdl;

        //
        // Register Interrupt handler
        //
        osi_InterruptRegister(INT_GPIOA2,(P_OSI_INTR_ENTRY)GPIOs2IntHandler, \
                                INT_PRIORITY_LVL_1);

        //
        // Enable Interrupt
        //
        MAP_GPIOIntClear(GPIOA2_BASE,GPIO_PIN_6);
        MAP_GPIOIntEnable(GPIOA2_BASE,GPIO_INT_PIN_6);
    }
}

//*****************************************************************************
//
//!  \brief Enables Push Button GPIO Interrupt
//!
//! \param[in] ucSwitch               Push Button Swich Enum - SW2,SW3
//!
//! \return none
//!
//
//*****************************************************************************
void Button_IF_EnableInterrupt(unsigned char ucSwitch)
{
    if(ucSwitch & SW2)
    {
        //Enable GPIO Interrupt
        MAP_GPIOIntClear(GPIOA2_BASE,GPIO_PIN_6);
        MAP_IntPendClear(INT_GPIOA2);
        MAP_IntEnable(INT_GPIOA2);
        MAP_GPIOIntEnable(GPIOA2_BASE,GPIO_PIN_6);
    }

    if(ucSwitch & SW3)
    {
         //Enable GPIO Interrupt
         MAP_GPIOIntClear(GPIOA1_BASE,GPIO_PIN_5);
         MAP_IntPendClear(INT_GPIOA1);
         MAP_IntEnable(INT_GPIOA1);
         MAP_GPIOIntEnable(GPIOA1_BASE,GPIO_PIN_5);
    }

    if(ucSwitch & SW4)
    {
         //Enable GPIO Interrupt
         MAP_GPIOIntClear(GPIOA3_BASE,GPIO_PIN_4);
         MAP_IntPendClear(INT_GPIOA3);
         MAP_IntEnable(INT_GPIOA3);
         MAP_GPIOIntEnable(GPIOA3_BASE,GPIO_PIN_4);
    }
}


//*****************************************************************************
//
//!  \brief Disables Push Button GPIO Interrupt
//!
//! \param[in] ucSwitch               Push Button Swich Enum - SW2,SW3
//!
//! \return none
//!
//
//*****************************************************************************
void Button_IF_DisableInterrupt(unsigned char ucSwitch)
{
    if(ucSwitch & SW2)
    {
        //Clear and Disable GPIO Interrupt
        MAP_GPIOIntDisable(GPIOA2_BASE,GPIO_PIN_6);
        MAP_GPIOIntClear(GPIOA2_BASE,GPIO_PIN_6);
        MAP_IntDisable(INT_GPIOA2);
    }

    if(ucSwitch & SW3)
    {
        //Clear and Disable GPIO Interrupt
        MAP_GPIOIntDisable(GPIOA1_BASE,GPIO_PIN_5);
        MAP_GPIOIntClear(GPIOA1_BASE,GPIO_PIN_5);
        MAP_IntDisable(INT_GPIOA1);
    }


    if(ucSwitch & SW4)
    {
        //Clear and Disable GPIO Interrupt
        MAP_GPIOIntDisable(GPIOA3_BASE,GPIO_PIN_4);
        MAP_GPIOIntClear(GPIOA3_BASE,GPIO_PIN_4);
        MAP_IntDisable(INT_GPIOA3);
    }
}
button_interface.h

Thanks & regards,

Farhan

  • Hello Farhan,

    There is a similar example working in the SDK but without the SW4, mqtt_client.

    Is this one working for you?

    Do you have the pins on pinmux.c file?

    What happens? if you put a breakpoint on the handlers it does not stop there?

    Regards,

    Shlomi

  • HI Shlomi,

    Thanks for your response.
    I just added sw4 from email example, sw2 and sw3 work but nothing happens when i pull sw4 (p17) to vcc from ground
    yeah I have added in pinmux.c

    MAP_PRCMPeripheralClkEnable(PRCM_GPIOA3, PRCM_RUN_MODE_CLK);

    //
    // Configure PIN_17 for GPIO Input
    //
    MAP_PinTypeGPIO(PIN_17, PIN_MODE_0, false);
    MAP_GPIODirModeSet(GPIOA3_BASE, 0x1, GPIO_DIR_MODE_IN);

    and interrupt related changes I have done in the files provided above
    I still can't understand what's wrong
    I tried changing pin I used other pins also but nothing seems to work

    Thanks & regards,
    Farhan
  • Hello Farhan,

    Is this a custom board or are you using the launchpad?

    In case you are using launchpad, please note that on the launchpad, this specific pin is used by the JTAG debugger.

    The pinmux looks OK.

    The only thing I can add is that you pull it from ground to Vcc but the trigger in your code is FALLING_EDGE.

    Regards,

    Shlomi

  • Hello Shlomi,

    I tried with pin50 also
    yup I did pulled it from ground to vcc

    I am using lanunchpad with QFN package

    I will try with some different pin and let you know

    Thanks & regards,
    Farhan

  • Hi Shlomi,

    The issue was with the hardware.
    Thanks for your help

    Thanks & regards,
    Farhan