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.

Tiva Input User Switch 2

Hello Guys.

I am trying to handle the user swithces on my Tiva Board.

Thanks to the Luis Electronic Projects I was able to use the User Switch 1 wich goes to PIN_F4 to toggle the RED_LED, but I didn't  make it via User Switch 2 wich goes at PIN_F0.

Here is the code

#include <stdint.h>
#include <stdbool.h>
#include "inc/hw_types.h"
#include "inc/hw_gpio.h"
#include "driverlib/pin_map.h"
#include "driverlib/sysctl.c"
#include "driverlib/sysctl.h"
#include "driverlib/gpio.c"
#include "driverlib/gpio.h"



#define LED_PERIPH SYSCTL_PERIPH_GPIOF
#define LED_BASE GPIO_PORTF_BASE
#define RED_LED GPIO_PIN_1

#define Button_PERIPH SYSCTL_PERIPH_GPIOF
#define ButtonBase GPIO_PORTF_BASE
#define Button GPIO_PIN_0     //In the original code Button is GPIO_PIN_4


int main(void)
{
 
 //Set the clock to 80Mhz
  SysCtlClockSet(SYSCTL_SYSDIV_2_5|SYSCTL_USE_PLL|SYSCTL_OSC_MAIN|SYSCTL_XTAL_16MHZ);

  SysCtlPeripheralEnable(LED_PERIPH);
  SysCtlDelay(3);
  
  GPIOPinTypeGPIOInput(ButtonBase, Button);
  GPIOPadConfigSet(ButtonBase ,Button,GPIO_STRENGTH_2MA,GPIO_PIN_TYPE_STD_WPU);
  
  GPIOPinTypeGPIOOutput(LED_BASE, RED_LED);
  
    
  uint32_t value=0;
  uint8_t state=0;
  while(1){
    value= GPIOPinRead(ButtonBase,Button);
    if( (value & GPIO_PIN_0)==0)
      state^=RED_LED;

    GPIOPinWrite(LED_BASE,RED_LED, state);
    SysCtlDelay(7000000);
  }
   
}

I dont understand where I am wrong. I just changed the GPIO_PIN macro. The interesting thing is that the LED is constantly toggling, as if the button is permanently pressed. Obviously the input function returns only '0' (button_pressed). I measured the voltage accros the buttons. In STATE_OPEN at the USER_SW_1 the voltage is approximately 3.2V and the voltage across the USER_SW_2 is 2.9V. May be the PULL Up current isn't enough to make the input high?

Thank you in advance fellows.

 

  • Hi Radoslav,

         See, this post below and my signature link regarding PF0.

         Diagnosing Common Development Problems and Tips for TM4C Devices

    - kel

  • Hello Radoslav,

    PF0 is a locked pin for NMI function. You would need to unlock it as mentioned by Kel (Thanks Kel)

    Regards

    Amit

  • It works this way!

    #define LED_PERIPH SYSCTL_PERIPH_GPIOF
    #define LED_BASE GPIO_PORTF_BASE
    #define RED_LED GPIO_PIN_1
    
    #define Button_PERIPH SYSCTL_PERIPH_GPIOF
    #define ButtonBase GPIO_PORTF_BASE
    #define Button GPIO_PIN_0
    
    
    int main(void)
    {
    	HWREG(GPIO_PORTF_BASE+GPIO_O_LOCK) = GPIO_LOCK_KEY;
    
    	HWREG(GPIO_PORTF_BASE+GPIO_O_CR) |= GPIO_PIN_0;
    
     //Set the clock to 80Mhz
      SysCtlClockSet(SYSCTL_SYSDIV_2_5|SYSCTL_USE_PLL|SYSCTL_OSC_MAIN|SYSCTL_XTAL_16MHZ);
    
    
      SysCtlPeripheralEnable(LED_PERIPH);
      SysCtlDelay(3);
    
      GPIOPinTypeGPIOInput(ButtonBase, Button);
      GPIOPadConfigSet(ButtonBase ,Button,GPIO_STRENGTH_2MA,GPIO_PIN_TYPE_STD_WPU);
    
    
      GPIOPinTypeGPIOOutput(LED_BASE, RED_LED);
    
    
      uint32_t value=0;
      uint8_t state=0;
      while(1){
        value= GPIOPinRead(ButtonBase,Button);
        if( (value & GPIO_PIN_0)==0)
          state^=RED_LED;
    
        GPIOPinWrite(LED_BASE,RED_LED, state);
        SysCtlDelay(7000000);
      }
    
    }

    You Guys are GREAT !!!

    Thank you again!