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.

How to toggle GPIO in TMS320F28027

Other Parts Discussed in Thread: TMS320F28027

Hello,

I wrote a small program for gpio toggle in tms320f28027. I am neither getting errors nor warnings. even if I have used infinite loop, they are toggling only once. I am posting my code too. please help me

/*

* main.c

*/

#include "DSP28X_Project.h"

 

void gpiotoggle(void);

void gpiosetup(void);

void delay(void);

 

 

void main(void)

{

       InitSysCtrl();

       gpiosetup();

       DINT;

       InitPieCtrl();

       IER = 0x0000;

       IFR = 0x0000;

       InitPieVectTable();

       gpiotoggle();

 

}

 

void delay(void)

{

       short i;

       for (i=0;i<1000;i++) {}

}

 

 

 

void gpiosetup(void)

{

       EALLOW;

       GpioCtrlRegs.GPAMUX1.all = 0x00000000; // All GPIO

       GpioCtrlRegs.GPAMUX2.all = 0x00000000; // All GPIO

       GpioCtrlRegs.GPAMUX1.all = 0x00000000; // All GPIO

       GpioCtrlRegs.GPADIR.all = 0xFFFFFFFF;   // All outputs

       GpioCtrlRegs.GPBDIR.all = 0x0000000F;   // All outputs

       EDIS;

}

 

void gpiotoggle(void)

{

 

       GpioDataRegs.GPASET.all = 0xAAAAAAAA;

       GpioDataRegs.GPACLEAR.all = 0x55555555;

       GpioDataRegs.GPASET.all = 0x0000000A;

       GpioDataRegs.GPACLEAR.all = 0x00000005;

       for(;;)

       {

              GpioDataRegs.GPATOGGLE.all = 0xAAAAAAAA;

              GpioDataRegs.GPATOGGLE.all = 0x0000000A;

              delay();

       }

}

 

  • Madhuri,

    Step the code in the for(;;) to debug.  Is the code looping?  Observe the GPIO pins on a scope.  Do they change state?

    Also, I suspect the code you show is not what you wanted to write.  The second set of GPASET, GPACLEAR, and GPATOGGLE should be GPBSET, GPBCLEAR, and GPBTOGGLE, based on what I think you are trying to do.

    Regards,

    David

  • Hello david.

    In response to your answer, I have altered my code to just toggle only GPIO1 pin. still its not working. no errors and warnings. but code is not running properly.Please help me

    /*

    * main.c

    */

    #include "DSP28X_Project.h"

     

    void gpiosetup(void);

    void gpiotoggle(void);

     

     

    int main(void)

    {

           InitSysCtrl();

           DINT;

           InitPieCtrl();

     

           IER = 0x0000;

           IFR = 0x0000;

     

           InitPieVectTable();

           gpiosetup();

           gpiotoggle();

          

    }

     

    void gpiosetup()

    {

           EALLOW;

           GpioCtrlRegs.GPAPUD.all = 0x00000002;

           GpioCtrlRegs.GPAMUX1.all= 0x00000000;

           GpioCtrlRegs.GPADIR.all = 0x00000002;

           EDIS;

    }

     

    void gpiotoggle()

    {

           EALLOW;

           int i;

           for (i=0;i<10;i++)

           {

                  GpioDataRegs.GPATOGGLE.all = 0x00000002;

           }

           EDIS;

    }

     

  • Madhuri,

    Again, you need to step the code to debug it.  Set a breakpoint in gpiotoggle().  Do you get there?  If so, step.  Does the code step through the for() loop and wrap around?

    - David

  • Madhuri,

    I agree with David here.

    Additionally, you have no way to catch the end of the code in main,.You may be running right through the ten iteration toggle and drop right out of main. Put either an ESTOP0  or a while(1); at the end of main to ensure that you stay in the maiin loop if you just click "Run" with the debugger.

    -Mark