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.