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.

TM4C1231D5PZ: Interrupt on Port C not triggered

Part Number: TM4C1231D5PZ

Hi

I am facing some interrupt issues.

Using below code, does not trigger my interrupt function.
(The button is pulled high and should go to 0 when pressed, this is confirmed using a scope)

If I change everything to do it polled (reading the pin in a while loop), I can see the correct value.
I suspect something wrong with my code.

(the 'print' function is something that works and is used multiple times within our code and is doing just fine)

void setup_rst() 
{
    GPIOPinTypeGPIOInput(GPIO_PORTC_BASE, GPIO_INT_PIN_5);

    GPIOIntClear(GPIO_PORTC_BASE, GPIO_INT_PIN_5);

    GPIOIntRegisterPin(GPIO_PORTC_BASE, GPIO_INT_PIN_5, rst_btn_pressed);
    GPIOIntTypeSet(GPIO_PORTC_BASE, GPIO_INT_PIN_5, GPIO_FALLING_EDGE);

    GPIOIntEnable(GPIO_PORTC_BASE, GPIO_PIN_5);
}   
    
void rst_btn_pressed()
{
    print((uint8_t *) "rst pressed\r\n");

}

  • Hi,

    I think you are missing the IntEnable(INT_GPIOC) and GPIOPadConfigSet(). You need to enable interrupt for PortC at the NVIC level which I don't see inside your setup_rst(). Same for missing the GPIOPadConfigSet() statement. See below example code to generate interrupts using PP0 and PP1. 

    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOP);
    while(!SysCtlPeripheralReady(SYSCTL_PERIPH_GPIOP))
    {
    }
    GPIOPinTypeGPIOInput(GPIO_PORTP_BASE, GPIO_PIN_0 | GPIO_PIN_1);
    GPIOPadConfigSet(GPIO_PORTP_BASE, GPIO_PIN_0 | GPIO_PIN_1, GPIO_STRENGTH_4MA, GPIO_PIN_TYPE_STD_WPU);
    GPIOIntTypeSet(GPIO_PORTP_BASE, GPIO_PIN_0 | GPIO_PIN_1, GPIO_FALLING_EDGE);


    GPIOIntRegisterPin(GPIO_PORTP_BASE, GPIO_PIN_0, UserButton1ISR);
    GPIOIntRegisterPin(GPIO_PORTP_BASE, GPIO_PIN_1, UserButton2ISR);

    GPIOIntEnable(GPIO_PORTP_BASE, GPIO_INT_PIN_0 | GPIO_INT_PIN_1);

    IntEnable(INT_GPIOP0);
    IntEnable(INT_GPIOP1);
    IntMasterEnable();

  • Hi Charles

    As soon as I add  IntEnable(INT_GPIOC), the controller crashes when the button is pressed.

    The peripheral was enabled before.
    Is the padconfig really needed?

  • Hi,

      Can you put a breakpoint at the beginning of your rst_btn_pressed? If the processor halts in the ISR then it confirms that your earlier problem was due to  interrupt not being enabled at the NVIC level. As for the crash, I think it may have something to do with your printf statement. Normally, printf requires a lot of stack and heap. We normally don't recommend printf but rather UARTPrintf() instead. If you really want to use printf, increase the heap and stack. You need the GPIOPadConfigSet so the internal pullup is enabled unless you have an external pullup in place. Sometime your external circuit may have initialized after the MCU. When this happens, the GPIO input is floating and you don't want false trigger. Normally I will have GPIOPadConfigSet. 

    #define APP_BASE 0x00000000
    #define RAM_BASE 0x20000000

    /* System memory map */

    MEMORY
    {
    /* Application stored in and executes from internal flash */
    FLASH (RX) : origin = APP_BASE, length = 0x00040000
    /* Application uses internal RAM for data */
    SRAM (RWX) : origin = 0x20000000, length = 0x00008000
    }

    /* Section allocation in memory */

    SECTIONS
    {
    .intvecs: > APP_BASE
    .text : > FLASH
    .const : > FLASH
    .cinit : > FLASH
    .pinit : > FLASH
    .init_array : > FLASH

    .vtable : > RAM_BASE
    .data : > SRAM
    .bss : > SRAM
    .sysmem : > SRAM
    .stack : > SRAM
    }

    __STACK_TOP = __stack + 2048;

  • Hi Charles

    Thanks for the explanation :)
    There is an external pullup (10K) to 3V3, so that should be fine.

    Setting the breakpoint at the start of the function, does not trigger.

    I followed your comment and removed the print statement.
    Now an int should be set, just so I can see it with a breakpoint :)

  • I found a solution.

    GPIOIntRegisterPin() does not doe what it is supposed to.
    I use the more general  GPIOIntRegister() now to register the interrupt.