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.

C2000 TMS320F28027 Button Status Problem

Hi,

Sorry for asking a simple question for you. I am trying to do a button example on C2000 F28027, I am using GPIO12 Button. But the system doesn't work. Whenever I push the button, the system input status always "1".

I copied the code. Did I make a mistake?

Sincerely,

#include "DSP28x_Project.h"

#define BUTTON_GPIO  GpioDataRegs.GPADAT.bit.GPIO12

void main(void){

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

    InitSysCtrl();

    EALLOW;

    GpioCtrlRegs.GPBMUX1.bit.GPIO34 = 0;
    GpioCtrlRegs.GPBDIR.bit.GPIO34 = 1;

    GpioCtrlRegs.GPAMUX1.bit.GPIO0 = 0;
    GpioCtrlRegs.GPAMUX1.bit.GPIO1 = 0;
    GpioCtrlRegs.GPAMUX1.bit.GPIO2 = 0;
    GpioCtrlRegs.GPAMUX1.bit.GPIO3 = 0;

    GpioCtrlRegs.GPADIR.bit.GPIO0 = 1;
    GpioCtrlRegs.GPADIR.bit.GPIO1 = 1;
    GpioCtrlRegs.GPADIR.bit.GPIO2 = 1;
    GpioCtrlRegs.GPADIR.bit.GPIO3 = 1;

    GpioCtrlRegs.GPAPUD.bit.GPIO12 = 0;  
    GpioCtrlRegs.GPAQSEL1.bit.GPIO12 = 3; 
    GpioCtrlRegs.GPAMUX1.bit.GPIO12 = 1;  

    EDIS;

    int status;

    while(1){

     status = BUTTON_GPIO;

    if (BUTTON_GPIO == 1){
        GpioDataRegs.GPASET.bit.GPIO0 = 1;
        GpioDataRegs.GPASET.bit.GPIO1 = 1;
        GpioDataRegs.GPASET.bit.GPIO2 = 0;
        GpioDataRegs.GPASET.bit.GPIO3 = 0;
    }

    else{
        GpioDataRegs.GPASET.bit.GPIO0 = 0;
        GpioDataRegs.GPASET.bit.GPIO1 = 0;
        GpioDataRegs.GPASET.bit.GPIO2 = 1;
        GpioDataRegs.GPASET.bit.GPIO3 = 1;
    }
    }
}

  • Hello Fethi,

    It looks like you are configuring GPAMUX1 for GPIO12 to be 1, this is not correct for a GPIO configuration. If you want to use the pin as a GPIO, you must set this bit to 0. You can confirm this in the GPIO Port A MUX 1 (GPAMUX1) Register section of the technical reference manual.

    Best regards,

    Omer Amir

  • Hi Omar,

    I did the same thing after your advice. But it didn't work again.

        GpioCtrlRegs.GPAMUX1.bit.GPIO12 = 0;  // GPIO12 = TZ1
        GpioCtrlRegs.GPAQSEL1.bit.GPIO12 = 3; // asynch input
        GpioCtrlRegs.GPADIR.bit.GPIO12 = 0;
        GpioCtrlRegs.GPAPUD.bit.GPIO12 = 0;   // Enable pullup on GPIO12

  • Hello Fethi,

    Have you confirmed with a scope that pressing the button applies a voltage? Have you checked the voltage level and pressed the button for a sufficient amount of time?

    Best regards,

    Omer Amir