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.

tm4c1294xl buttons...

heyo fellow forumers.. been trying to set up a button to turn on and off an led... and can't... don't know why.

the board I'm using is the tm4c1294xl. I'm using CCS v.6.1

here is the code I've written;

#include <stdbool.h>

#include <stdint.h>

#include "inc/hw_types.h"

#include "inc/hw_gpio.h"

#include "inc/hw_memmap.h"

#include "driverlib/gpio.h"

#include "driverlib/pin_map.h"

#include "driverlib/pwm.h"

#include "driverlib/sysctl.h"

#include "drivers/pinout.h"

int main(void){

//enable the first LED (PN1)

SysCtlPeripheralEnable(SYSCTL_PERIPH_GPION);

GPIOPinTypeGPIOOutput(GPIO_PORTN_BASE, GPIO_PIN_0);

//Enable The first push button (PJ0)

SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOJ);

GPIOPinTypeGPIOInput(GPIO_PORTJ_BASE, GPIO_PIN_0);

GPIOPadConfigSet(GPIO_PORTJ_BASE, GPIO_PIN_0, GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD_WPU);

while(1)

{

int buttonpressed = GPIOPinRead(GPIO_PORTJ_BASE, GPIO_PIN_0);

if(buttonpressed != 0)

{

GPIOPinWrite(CLP_D1_PORT, CLP_D1_PIN, CLP_D1_PIN);

}

else

{

GPIOPinWrite(CLP_D1_PORT, CLP_D1_PIN, 0);

}

GPIOIntClear(GPIO_PORTJ_BASE, GPIO_PIN_0);

}

}

thanks much.

  • Hello Bryce,

    The first thing to check on the LaunchPad is when the PJ0 is configured as a GPIO with Pull Up does it show 3.3V and when the button is pressed does it go to 0V.
    Secondly, if you toggle the PN0 pin high and low using the debugger, does it light up the LED
    Thirdly, what is CLP_D1_PORT and CLP_D1_PIN?

    Regards
    Amit
  • i was addressing things slightly incorrectly, the voltage wasn't showing and the led wasn't firing.
    the CLP_D1_PORT and CLP_D1_PIN comes from the pinout.h/pinout.c files and is a "simple" way of addressing the LED's... here is the corrected code, the buttons now work in controlling the LED.

    #include <stdbool.h>
    #include <stdint.h>
    #include "inc/hw_types.h"
    #include "inc/hw_gpio.h"
    #include "inc/hw_memmap.h"
    #include "driverlib/gpio.h"
    #include "driverlib/pin_map.h"
    #include "driverlib/pwm.h"
    #include "driverlib/sysctl.h"
    #include "drivers/pinout.h"

    int main(void)
    {

    //enable the first LED (PN1)
    //enable port N
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPION);
    //declare N1 is the output
    GPIOPinTypeGPIOOutput(GPIO_PORTN_BASE, GPIO_PIN_1);

    //Enable The first push button (PJ0)
    //enable port J
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOJ);
    //declare J0 is an input
    GPIOPinTypeGPIOInput(GPIO_PORTJ_BASE, GPIO_PIN_0);
    //declare what type of button function we want
    GPIOPadConfigSet(GPIO_PORTJ_BASE, GPIO_PIN_0, GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD_WPU);

    while(1){

    int buttonpressed = GPIOPinRead(GPIO_PORTJ_BASE, GPIO_PIN_0);

    if(buttonpressed != 0)

    {

    GPIOPinWrite(GPIO_PORTN_BASE, GPIO_PIN_1, 0);

    }

    else

    {

    GPIOPinWrite(GPIO_PORTN_BASE, GPIO_PIN_1, 2);

    }

    GPIOIntClear(GPIO_PORTJ_BASE, GPIO_PIN_0);

    }

    }