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.

TMS320F280025C: Debugging button Debounce in tms320f280025c

Part Number: TMS320F280025C
Other Parts Discussed in Thread: C2000WARE

Tool/software:

Hi iam working on TMS320F280025C launchpad ,iam trying to use one gpio pin as button and trying to control the LED using this GPIO pin which i have taken as an input.But iam not getting any expected result.Below is my code please suggest any changes to make .

#include "driverlib.h"
#include "device.h"
#include "board.h"
#include "c2000ware_libraries.h"

//
// Main
//

#define LED_GPIO 31 // Onboard LED (GPIO0)
#define BUTTON_GPIO 42 // Use GPIO24 for custom button (J1.14 header pin)


void main(void)
{

//

//
Device_init();

//
// Disable pin locks and enable internal pull-ups.
//
Device_initGPIO();

//
// Initialize PIE and clear PIE registers. Disables CPU interrupts.
//
Interrupt_initModule();

//
// Initialize the PIE vector table with pointers to the shell Interrupt
// Service Routines (ISR).
//
Interrupt_initVectorTable();

//
// PinMux and Peripheral Initialization
//
Board_init();

//
// C2000Ware Library initialization
//
C2000Ware_libraries_init();
;
EINT;
ERTM;
GPIO_setPadConfig(LED_GPIO, GPIO_PIN_TYPE_STD);
GPIO_setDirectionMode(LED_GPIO, GPIO_DIR_MODE_OUT);
// GPIO_writePin(LED_GPIO, 1); // Start with LED ON

// Configure BUTTON_GPIO as input with pull-up
GPIO_setPadConfig(BUTTON_GPIO, GPIO_PIN_TYPE_PULLUP);
GPIO_setDirectionMode(BUTTON_GPIO, GPIO_DIR_MODE_IN);
GPIO_setQualificationMode(BUTTON_GPIO, GPIO_QUAL_SYNC);

while(1)
{
// Read current button state (0 = pressed, 1 = released)
bool buttonState = GPIO_readPin(BUTTON_GPIO);

// If jumper connected (LOW), turn LED off
if(buttonState == 0)
{
GPIO_writePin(LED_GPIO, 1);
}
else // Jumper not connected (HIGH)
{
DEVICE_DELAY_US(5000);
GPIO_writePin(LED_GPIO, 0);
}
DEVICE_DELAY_US(5000);
}
}

  • Hello, Sairaj.

    Looks like your LED configuration is good. However, your external button configuration and comments seem to conflict.

    #define BUTTON_GPIO 42 // Use GPIO24 for custom button (J1.14 header pin)

    You have the integer value defined as 42, which is LaunchPad pin 34. However the comments suggest GPIO 24 (maybe a typo for 42, but if not will connect to LaunchPad pin 44).

    Based on the current code configuration, please ensure that the external button is connected to GPIO42, pin 34 (see image below, red boxes highlight the identified pin):

    Best,

    Ryan