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.

EK-TM4C123GXL: Detecting SW2

Part Number: EK-TM4C123GXL

My code below detects SW1 - but doesn't detect SW2 - but think I'm configuring both the same ...

Not sure what I'm missing here

    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);
    GPIOPinTypeGPIOInput(GPIO_PORTF_BASE, GPIO_PIN_4); // SW1
    GPIOPinTypeGPIOInput(GPIO_PORTF_BASE, GPIO_PIN_0); // SW2
    GPIODirModeSet(GPIO_PORTF_BASE, GPIO_PIN_4, GPIO_DIR_MODE_IN);
    GPIODirModeSet(GPIO_PORTF_BASE, GPIO_PIN_0, GPIO_DIR_MODE_IN);
    GPIOPadConfigSet(GPIO_PORTF_BASE, GPIO_PIN_4,
		     GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD_WPU); 
    GPIOPadConfigSet(GPIO_PORTF_BASE, GPIO_PIN_0,
		     GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD_WPU);

    int32_t SWstatus=GPIOPinRead(GPIO_PORTF_BASE,
					    GPIO_PIN_4|GPIO_PIN_0)^17;

  • And probably worth adding if I merge both buttons everywhere with GPIO_PIN_4 | GPIO_PIN_0 it makes no difference ...

  • Hi David,

      PF0 is a special pin. To reconfigure it, you need to unlock it first. 

    I tried the below code and it is working for me.  I put a breakpoint at SW2handler and it will stop at the ISR. 

    uint32_t count=0;
    
    void SW2Handler (void)
    {
        GPIOIntClear(GPIO_PORTF_BASE, GPIO_PIN_0);
        count++;
    
    }
    //*****************************************************************************
    //
    // Blink the on-board LED.
    //
    //*****************************************************************************
    int
    main(void)
    {
        volatile uint32_t ui32Loop;
        uint32_t lock_value = 0xFFFFFFFF;
    
    
        //
        // Enable the GPIO port that is used for the on-board LED.
        //
        SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);
    
        //
        // Check if the peripheral access is enabled.
        //
        while(!SysCtlPeripheralReady(SYSCTL_PERIPH_GPIOF))
        {
        }
        HWREG(GPIO_PORTF_BASE+GPIO_O_LOCK) = GPIO_LOCK_KEY;
        HWREG(GPIO_PORTF_BASE+GPIO_O_CR) |= GPIO_PIN_0;
        lock_value = HWREG(GPIO_PORTF_BASE+GPIO_O_LOCK);
    
        GPIOPinTypeGPIOInput(GPIO_PORTF_BASE, GPIO_PIN_0);
        GPIOPadConfigSet(GPIO_PORTF_BASE, GPIO_PIN_0, GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD_WPU);
        GPIOIntTypeSet(GPIO_PORTF_BASE, GPIO_PIN_0, GPIO_FALLING_EDGE);
        GPIOIntRegister(GPIO_PORTF_BASE, SW2Handler);
        GPIOIntEnable(GPIO_PORTF_BASE, GPIO_INT_PIN_0);
        IntEnable(INT_GPIOF);
        IntMasterEnable();
    
        // Loop forever.
        //
        while(1)
        {
        }
    }

  • Ta - that worked. Had to include hw_types.h and hw_gpio.h; and couldn't set lock_value so removed that bit. Which document did you get that from? I though I recalled SW2 had some special function, but didn't find you text in a document.

  • Hi David,

    FYI we also have a new TivaWare API for this in 2.2.0 if you use that version: 

    GPIOUnlockPin(GPIO_PORTF_BASE, GPIO_PIN_0);

    Table Charles showed is from device datasheet Slight smile.

    Best Regards,

    Ralph