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.

LAUNCHXL-F28027: F28027

Part Number: LAUNCHXL-F28027
Other Parts Discussed in Thread: DRV8353

I have bought the DRV8353_EVM which consists of two boards one of them is the LAUNCHXL-F280. I have started to familiarize myself microcontroller (F2802727) that is used in the evm and have encountered some strange behavior. I am trying to read the state of an IO pin that is connected to a button. If the button is pressed I want to turn on the four LEDs that is connected to GPIO0-GPIO3. The button is connected to GPIO12 which is pulled low when the button is released.

In the attached c-file there are two examples that can run. The one that is active when the macro SECOND is defined works as intended but the other, active when FIRST is defined, is not. What happens is that GpioDataRegs.GPADAT.bit.BTN is never cleared after a the button has been pressed and released. This does not happen when I run the code that is active when the macro SECOND is defined. Does anyone know what is happening here?

btn_leds.c
#include "DSP28x_Project.h"     // Device Headerfile and Examples Include File

#define FIRST
//#define SECOND

#define LED0    GPIO0
#define LED1    GPIO1
#define LED2    GPIO2
#define LED3    GPIO3
#define BTN     GPIO12

#define MIN_DELAY   10

enum dir {left, right};

void system_init(void);
void gpio_init(void);
void led_rider(void);


void main(void) {

    system_init();
    gpio_init();

    while(1) {
        

#ifdef FIRST
        if (GpioDataRegs.GPADAT.bit.BTN) {

            // The cathode of the led is connected to GPIO pin via a buffer
            // IC, thus LEDs are turned on when the io is set to zero...
            GpioDataRegs.GPACLEAR.bit.LED0  = 1;
            GpioDataRegs.GPACLEAR.bit.LED1  = 1;
            GpioDataRegs.GPACLEAR.bit.LED2  = 1;
            GpioDataRegs.GPACLEAR.bit.LED3  = 1;

        } else {

            GpioDataRegs.GPASET.bit.LED0    = 1;
            GpioDataRegs.GPASET.bit.LED1    = 1;
            GpioDataRegs.GPASET.bit.LED2    = 1;
            GpioDataRegs.GPASET.bit.LED3    = 1;

        }

#endif

#ifdef SECOND
        if (GpioDataRegs.GPADAT.bit.BTN) {
            led_rider();
            DELAY_US(10000);
        }
#endif
    }
}


void gpio_init(void) {

    EALLOW;

    GpioCtrlRegs.GPAMUX1.bit.LED0 = 0; // GPIO as GPIO
    GpioCtrlRegs.GPAMUX1.bit.LED1 = 0; // GPIO as GPIO
    GpioCtrlRegs.GPAMUX1.bit.LED2 = 0; // GPIO as GPIO
    GpioCtrlRegs.GPAMUX1.bit.LED3 = 0; // GPIO as GPIO
    GpioCtrlRegs.GPAMUX1.bit.BTN  = 0; // GPIO as GPIO

    GpioCtrlRegs.GPADIR.bit.LED0 = 1; // Outputs
    GpioCtrlRegs.GPADIR.bit.LED1 = 1; // Outputs
    GpioCtrlRegs.GPADIR.bit.LED2 = 1; // Outputs
    GpioCtrlRegs.GPADIR.bit.LED3 = 1; // Outputs
    GpioCtrlRegs.GPADIR.bit.BTN  = 0; // Inputs

    EDIS;
}

void system_init() {

#ifdef _FLASH
    memcpy(&RamfuncsRunStart, &RamfuncsLoadStart, (size_t)&RamfuncsLoadSize);
#endif

    InitSysCtrl();

    DINT;

    InitPieCtrl();

    IER = 0x0000;
    IFR = 0x0000;

    InitPieVectTable();

}

void led_rider() {

    static enum dir dir = left;

    static uint16_t led_pos = 1;

    GpioDataRegs.GPADAT.bit.LED0  = ~(led_pos & 1);
    DELAY_US(MIN_DELAY);

    GpioDataRegs.GPADAT.bit.LED1  = ~((led_pos & 2) >> 1);
    DELAY_US(MIN_DELAY);

    GpioDataRegs.GPADAT.bit.LED2  = ~((led_pos & 4) >> 2);
    DELAY_US(MIN_DELAY);

    GpioDataRegs.GPADAT.bit.LED3  = ~((led_pos & 8) >> 3);
    DELAY_US(MIN_DELAY);

    if (dir == left) {
        led_pos = (led_pos << 1);
        if (led_pos == 8) dir = right;
    } else {
        led_pos = (led_pos >> 1);
        if (led_pos == 1) dir = left;
    }
}

Best regards / Christoffer