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.

CCS/TM4C123GH6PM: CONFIGURE GPIO PIN AS INTERRUPT

Part Number: TM4C123GH6PM

Tool/software: Code Composer Studio

Hi,

    I have a idea about the general configuration about the GPIO and concept of the interrupt also. Can any provide me some detail information about how to configure the GPIO pin as interrupt, i gone through the example present the interrupt.c file. I getting the  information but not clearly. So can anyone provide me detailed information. Steps for the configuring the GPIO as interrupt.  Thanks in advance.

  • Here is an example from the TIVA Ware Peripheral driver User's Guide:

    	int32_t i32Val;
    //
    // Enable the GPIOA peripheral
    //
    	SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
    //
    // Wait for the GPIOA module to be ready.
    //
    	while(!SysCtlPeripheralReady(SYSCTL_PERIPH_GPIOA))
    	{
    	}
    //
    // Register the port-level interrupt handler. This handler is the first
    // level interrupt handler for all the pin interrupts.
    //
    	GPIOIntRegister(GPIO_PORTA_BASE, PortAIntHandler);
    //
    // Initialize the GPIO pin configuration.
    //
    // Set pins 2, 4, and 5 as input, SW controlled.
    //
    	GPIOPinTypeGPIOInput(GPIO_PORTA_BASE, GPIO_PIN_2 | GPIO_PIN_4 | GPIO_PIN_5);
    //
    // Set pins 0 and 3 as output, SW controlled.
    //
    	GPIOPinTypeGPIOOutput(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_3);//
    // Make pins 2 and 4 rising edge triggered interrupts.
    //
    	GPIOIntTypeSet(GPIO_PORTA_BASE, GPIO_PIN_2 | GPIO_PIN_4, GPIO_RISING_EDGE);
    //
    // Make pin 5 high level triggered interrupts.
    //
    	GPIOIntTypeSet(GPIO_PORTA_BASE, GPIO_PIN_5, GPIO_HIGH_LEVEL);
    //
    // Read some pins.
    //
    	i32Val = GPIOPinRead(GPIO_PORTA_BASE,(GPIO_PIN_0 | GPIO_PIN_2 | GPIO_PIN_3 | 	GPIO_PIN_4 | GPIO_PIN_5));
    //
    // Write some pins. Even though pins 2, 4, and 5 are specified, those pins
    // are unaffected by this write because they are configured as inputs. At
    // the end of this write, pin 0 is low, and pin 3 is high.
    //
    	GPIOPinWrite(GPIO_PORTA_BASE,(GPIO_PIN_0 | GPIO_PIN_2 | GPIO_PIN_3 |	GPIO_PIN_4 | GPIO_PIN_5),
    		(GPIO_PIN_3 | GPIO_PIN_4 | GPIO_PIN_5 | GPIO_PIN_6 |	GPIO_PIN_7));
    //
    // Enable the pin interrupts.
    //
    	GPIOIntEnable(GPIO_PORTA_BASE, GPIO_PIN_2 | GPIO_PIN_4 | GPIO_PIN_5);

  • Vendor's Bob has well answered poster's "GPIO Interrupt" question here.       However - there is a subtle difference in the coding of such "GPIO Interrupts" - when compared/contrasted to "MCU Peripheral Interrupts."

    My intent is to highlight that difference - as those arriving here may attempt to "model" this "GPIO Interrupt code format" for use by "Peripheral Interrupts" - and that cannot succeed!

    Note the last function call w/in the supplied, vendor coded example:    (above)

    "GPIOIntEnable(GPIO_PORTA_BASE, GPIO_PIN_2 | GPIO_PIN_4 | GPIO_PIN_5);"

    In the case of GPIO Interrupts - this proves sufficient - yet in ALL "Peripheral Interrupt" encodings - one more function call IS required!

    Follows two examples to effectively illustrate:   (note the two function calls w/in highlight - absolutely "required by such Peripheral Interrupts")

    PWMIntEnable(PWM0_BASE, PWM_INT_GEN_0);
    IntEnable(INT_PWM0_0);

    TimerIntEnable(WTIMER0_BASE, TIMER_TIMA_TIMEOUT);
    IntEnable(INT_WTIMER0A); 

    The GPIO based interrupt "escapes" this (extra) function call requirement - yet it must be employed - when attempting to fully enable,  "Peripheral Interrupts!"       This holds true as, "Each interrupt source can be individually enabled via IntEnable()."         (and individually disabled via  IntDisable() - when and if - that is desired.)

    For those sufficiently masochistic - or bored enough - to seek (yet more) the following invites:  "https://e2e.ti.com/support/microcontrollers/tiva_arm/f/908/p/605306/2227949#2227949"

    [edit]  Neither firm nor I employ "Tivaware" - yet our preferred, "StellarisWare"  (suggests) that  it (may) prove necessary to deploy, "GPIOPinIntEnable()" to  fully/properly enable individual pin interrupts and interrupt sources.      (that exercise - left to the (curious) reader...)

  • Thanks for the reply now GPIO interrupt clearly understood with your example given above.

    regards

    Niranjan Kumar.C.D