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.

TM4C123GH6PM: Generate Interrupts on pressing on-board switches

Part Number: TM4C123GH6PM
Other Parts Discussed in Thread: EK-TM4C123GXL,

Hello.

I am trying to generate interrupts on pressing SW1 (PF4) on TIVA C Series Launchpad. For some reason, the interrupt service routine won't hit (verified using break points). I have configured the GPIO as follows:

void gpio_config()
{

    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);

    GPIOPinTypeGPIOInput(GPIO_PORTF_BASE, GPIO_PIN_4);

    IntEnable(INT_GPIOF);

    GPIOPadConfigSet(GPIO_PORTF_BASE, GPIO_PIN_4, GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD_WPU);

    GPIOIntDisable(GPIO_PORTF_BASE, GPIO_PIN_4);

    GPIOIntClear(GPIO_PORTF_BASE, GPIO_PIN_4);

    GPIOIntRegister(GPIO_PORTF_BASE, ir_received);

    GPIOIntTypeSet(GPIO_PORTF_BASE, GPIO_PIN_4, GPIO_FALLING_EDGE);

    GPIOIntEnable(GPIO_PORTF_BASE, GPIO_PIN_4);
}

I'm new to this so might be missing something very basic here. Any help is much appreciated.

Thanks.

  • Did you call "IntMasterEnable();?" (or "MAP_IntMasterEnable();"?) You might want to import and run the example project from TivaWare in: "C:\ti\TivaWare_C_Series-2.1.4.178\examples\boards\ek-tm4c123gxl\interrupts"
  • Thanks for the reply.

    Yes, i have called "Rom_IntMasterEnable();" before i call "gpio_config()". I am editing that same example to better suit my application. Also went through gpio_jtag example. Maybe i need to unlock PORT_F before i can use it?! Just a hunch..
  • I can't seem to find anything wrong.
    However, you configure your pin as GPIOInput "too fast" after enabling the peripheral - as a good practice, add a line to wait for the peripheral to be ready after you continue.
    If that does not solve your matter, run a checklist of the registers involved... it is boring, but it will probably show what is missing...
    And you could show your ISR code as well, so that other can take a look and maybe help.
    Bruno
  • Hey Bruno.

    The problem seems to be with PF4 and PF0 pin in particular. I tried using other pins (PB0 and PB1), and the code works perfectly. Tried unlocking PF0 as follows:

    // Unlock PF0

    HWREG(GPIO_PORTF_BASE + GPIO_O_LOCK) = GPIO_LOCK_KEY; // Unlock CR register.
    HWREG(GPIO_PORTF_BASE + GPIO_O_CR) = 0x01; // Commit register.
    HWREG(GPIO_PORTF_BASE + GPIO_O_AFSEL) &= 0xfe; // 0 value signifies use of GPIO registers.

    This doesn't do the job as well. Not sure if i'm doing it right. I only blink LEDs in ISR as of now, yet to add the full functionality. Any idea why PF0 and PF4 are not getting configured to raise interrupts?

    Sudeep
  • Sudeep,
    On tm4c123gh6pm, PF0 is in fact locked. PF4 is NOT. Hence, PF4 should work.
    If you look at PF0 registers after trying to change them without unlocking, you shall see that they did not change.
    Take a look on other forum posts as how to unlock. Datasheet mentions one other register that you did not touch:

    "This pin is configured as a GPIO by default but is locked and can only be reprogrammed by unlocking the
    pin in the GPIOLOCK register and uncommitting it by setting the GPIOCR register."

    But don't forget to add the good practice of waiting for the peripheral to be ready after enabling it.

    Regards
    Bruno
  • Hey Bruno.

    Thanks for the tip on waiting for the peripheral to be ready after enabling it. 

    I went through the data sheet and it does say only PF0 is locked. I tried adding a small delay after enabling PF4 to no avail. Can't seem to figure out what else to do to configure PF4.

    Anyways, will look into unlocking PF0 for now, and try to get that to work.

    Regards,

    Sudeep

  • Hi Sudeep! A few more blank suggestions:
    - The delay should be after enabling the peripheral, not after "enabling" PF4... - SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);
    - Step debug your code and look at the register values after each change. If you are really suspicious, debug into (F5) the TivaWare calls and see them changing bit by bit - compare that to a working set on the different pins. It might be some typo that we did not spot in your code, you will find it.
    - Scope probe the input signal - is there really a signal coming into the pin?
    - Buy gasoline, apply 50ml on the board, lit a match onto it - preferably on an external, bare location. Buy new hardware and start from scratch...
    Try not to reach step 3, ok?
    Cheers
    Bruno
  • Bruno - should you NOT advise poster that - like PF0 - the "gasoline port" (PGx) is also "Locked" and must be "freed" prior to use?