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.

software trigger of an interrupt in TM4C1294

Hi Everyone,

I need to Trigger my GPIO Interrupts through a Software call . How do I do this?

My Code Below:

void PortJIntHandler(void)
{
    uint32_t delay=0;

        GPIOIntClear(GPIO_PORTJ_BASE, GPIO_INT_PIN_0);
        GPIOPinWrite(GPIO_PORTN_BASE, GPIO_PIN_1,
                                (GPIOPinRead(GPIO_PORTN_BASE, GPIO_PIN_1) ^
                                                GPIO_PIN_1));
        for(delay=0;delay<10000;delay++);                     //some delay
}

void interrupt_initialise(void)
{

    /*
        Configure the switch on the left of the launchpad, SW1 to a input with
        internal pull-up.
      */
      GPIOPinTypeGPIOInput(GPIO_PORTJ_BASE, GPIO_PIN_0);
      GPIOPadConfigSet(GPIO_PORTJ_BASE ,GPIO_PIN_0,GPIO_STRENGTH_2MA,GPIO_PIN_TYPE_STD_WPU);
      GPIOIntDisable(GPIO_PORTJ_BASE, GPIO_INT_PIN_0);
      GPIOIntTypeSet(GPIO_PORTJ_BASE,GPIO_PIN_0,GPIO_FALLING_EDGE);
      GPIOIntRegister(GPIO_PORTJ_BASE,PortJIntHandler);
      for(g_ui32delay=0;g_ui32delay<10000;g_ui32delay++);                   //some delay
      GPIOIntEnable(GPIO_PORTJ_BASE, GPIO_INT_PIN_0);
      for(g_ui32delay=0;g_ui32delay<25000;g_ui32delay++);                   //some delay
}

int
main(void)
{
    PinoutSet();
    ROM_IntMasterEnable();
    interrupt_initialise();


    while(1)
    {
    	SysCtlDelay(16000000);
    	IntTrigger(INT_GPIOJ | GPIO_INT_PIN_0);  //I Need to call the Interrupt here!!!
    }
}

Thanks for the Help in advance...

Regards,
Girish.

  • Hello,
    I will move this thread to the the TM4C forums, where the experts there can help you best.

    Thanks
    ki
  • Hell Girish

    To software trigger an interrupt call the API IntTrigger(<INT NAME>). Include the file interrupt.h

    Also do make sure that the Interrupt is enabled by the API IntEnable(<INT NAME>)

    Regards
    Amit
  • Hello Amit,

    Thanks for your fast response. I have indeed included the interrupt.h file in my code. Attached herewith is the list of include files. still the code does not work.

    My Includes list:

    #include <stdbool.h>
    #include <stdint.h>
    #include "inc/hw_memmap.h"
    #include "driverlib/debug.h"
    #include "driverlib/gpio.h"
    #include "driverlib/rom.h"
    #include "driverlib/sysctl.h"
    #include "pinout.h"
    #include "userdefines.h"
    #include "inc/hw_ints.h"
    #include "driverlib/interrupt.h"
    

    Regards,

    Girish.

  • Hello Girish

    What does not work?

    Have you registered the interrupt handler PortJIntHandler in the startup file. The other thing is that there is a lot of delay added. Not a good idea.

    Regards
    Amit
  • Hello Amit,
    Yes I have registered the interrupt handler . Please verify the very first code, I have sent, line #23 :
    GPIOIntRegister(GPIO_PORTJ_BASE,PortJIntHandler);
    I did remove all the delays and saw.. But there are no results. The interrupt handler is not called when we execute the line:
    IntTrigger(INT_GPIOJ | GPIO_INT_PIN_0);.. This is what I meant by saying, it does not work. I had put those delays only to enable me to run to those lines in code composer studio. Hence, I am not able to software trigger the interrupts.

    Regards,
    Girish.
  • Hello Girish

    Your code is not visible and the trigger is always done as follows.

    IntTrigger(INT_GPIOJ);

    Regards
    Amit
  • Dear Amit,
    I tried with code:
    IntTrigger(INT_GPIOJ);
    There was no results. Hence, I thought that as the interrupt is intialised oh Port J-pin 0, so I tried this code:
    IntTrigger(INT_GPIOJ | GPIO_INT_PIN_0);
    But, this also did not yield the output.

    Regards,
    Girish.
  • Hello Girish

    Your full updated code is not visible yet... Also if you have mapped the interrupt handler in the startup file, there is no need for GPIOIntRegister function call.

    Regards
    Amit
  • Dear Amit,
    In the startup_ccs.c file, I have not mapped the interrupt handler and so, I am doing it here...

    Regards,
    Girish.
  • Hello Girish,

    This is going to waste precious SRAM. Calling the function from startup v/s calling it via Intregister API, causes vector table to be relocated to SRAM which will reduce available SRAM by 1K.

    And as usual for the 3rd time, full updated code is not visible?

    Regards
    Amit
  • Dear Amit,

    Thanks for your suggestion. In my working code, I shall certainly implement your advice. I am re pasting my code. Hopefully, you can view my code this time.

    #include <stdbool.h>
    #include <stdint.h>
    #include "inc/hw_memmap.h"
    #include "driverlib/debug.h"
    #include "driverlib/gpio.h"
    #include "driverlib/rom.h"
    #include "driverlib/sysctl.h"
    #include "pinout.h"
    #include "userdefines.h"
    #include "inc/hw_ints.h"
    #include "driverlib/interrupt.h"
    
    void PortJIntHandler(void)
    {
        GPIOIntClear(GPIO_PORTJ_BASE, GPIO_INT_PIN_0);
        GPIOPinWrite(GPIO_PORTN_BASE, GPIO_PIN_1,
                               (GPIOPinRead(GPIO_PORTN_BASE, GPIO_PIN_1) ^
                                            GPIO_PIN_1));        
    }
    
    void interrupt_initialise(void)
    {
    
        /*
            Configure the switch on the left of the launchpad, SW1 to a input with
            internal pull-up.
          */
          GPIOPinTypeGPIOInput(GPIO_PORTJ_BASE, GPIO_PIN_0);
          GPIOPadConfigSet(GPIO_PORTJ_BASE ,GPIO_PIN_0,GPIO_STRENGTH_2MA,GPIO_PIN_TYPE_STD_WPU);
          GPIOIntDisable(GPIO_PORTJ_BASE, GPIO_INT_PIN_0);
          GPIOIntTypeSet(GPIO_PORTJ_BASE,GPIO_PIN_0,GPIO_FALLING_EDGE);
          GPIOIntRegister(GPIO_PORTJ_BASE,PortJIntHandler);
          GPIOIntEnable(GPIO_PORTJ_BASE, GPIO_INT_PIN_0);
          for(g_ui32delay=0;g_ui32delay<25000;g_ui32delay++);                   //some delay
    }
    
    int
    main(void)
    {
        PinoutSet();
        ROM_IntMasterEnable();
        interrupt_initialise();
    
    
        while(1)
        {
            SysCtlDelay(16000000);
            IntTrigger(INT_GPIOJ | GPIO_INT_PIN_0);  //I Need to call the Interrupt here!!!
        }
    }

  • Hello Girish

    It seems that you have not taken two important recommendations

    1. IntTrigger(INT_GPIOJ | GPIO_INT_PIN_0); needs to be IntTrigger(INT_GPIOJ);

    2. IntEnable(INT_GPIOJ) is missing

    Regards
    Amit Ashara
  • Dear Amit,

    I did include the IntEnable(INT_GPIOJ)  in my initialise code and now my revised initialise code is shown below:

    void interrupt_initialise(void)
    {
    
        /*
            Configure the switch on the left of the launchpad, SW1 to a input with
            internal pull-up.
          */
          /*GPIOPinTypeGPIOInput(GPIO_PORTJ_BASE, GPIO_PIN_0);
          GPIOPadConfigSet(GPIO_PORTJ_BASE ,GPIO_PIN_0,GPIO_STRENGTH_2MA,GPIO_PIN_TYPE_STD_WPU);*/
          GPIOIntDisable(GPIO_PORTJ_BASE, GPIO_INT_PIN_0);
          GPIOIntTypeSet(GPIO_PORTJ_BASE,GPIO_PIN_0,GPIO_FALLING_EDGE);
          GPIOIntRegister(GPIO_PORTJ_BASE,PortJIntHandler);
          GPIOIntEnable(GPIO_PORTJ_BASE, GPIO_INT_PIN_0);
          IntEnable(INT_GPIOJ);
          for(g_ui32delay=0;g_ui32delay<25000;g_ui32delay++);
    }

    But now the program is running to interrupt fault handler routine as shown below:

    static void
    IntDefaultHandler(void)
    {
        //
        // Go into an infinite loop.
        //
        while(1)
        {
        }
    }

    Please Advice....

    Regards,

    Girish.

  • Hello Girish,

    Simplify.... As I have mentioned to you time and again

    GPIOIntRegister(GPIO_PORTJ_BASE,PortJIntHandler); is not required, when the micro controller simplifies the operation. Instead put the function PortJIntHandler in the startup file at the position of the interrupt vector entry for Port J.

    Regards
    Amit
  • Dear Amit,

    Thanks...I tried out the code late evening and it did work....Thanks again, for sparing your valuable time and showing interest in resolving the issue. I do heartily appreciate the involvement of the TI team in extending the much needed support for people who migrate from controllers from other manufacturers to TI Controllers. Keep up the Good work Guys!!!

    REgards,

    Girish.

  • Hello Girish

    Normally we do avoid using any IntRegister as it does affect the user available SRAM.

    Regards
    Amit
  • Dear Amit,
    As I am new to TI Micro-controllers, for knowledge sake I am asking, in that case, why is the IntRegister API Provided? Is there any special significance or situation when we cannot access the memory map and we need to assign the interrupt handler, only using this API?

    Regards,
    Girish.
  • Hello Girish,

    In some cases users want to have two or more different handlers in software where it make sense.

    Regards
    Amit