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.

CCS/TMS320F28377S: Problem with GpioDataRegs

Part Number: TMS320F28377S

Tool/software: Code Composer Studio

I wrote a code to blink the two leds on the launchpad connected to Gpio13,Gpio12 to blink simultaneously but it didnot work

#include "F28x_Project.h"
void main()
{uint32_t delay;
InitSysCtrl();
InitGpio();
EALLOW;
GpioCtrlRegs.GPADIR.bit.GPIO12=1;
GpioCtrlRegs.GPADIR.bit.GPIO13=1;
GpioCtrlRegs.GPAMUX1.bit.GPIO12=0;
GpioCtrlRegs.GPAMUX1.bit.GPIO13=0;
EDIS;


while(1)
{
GpioDataRegs.GPADAT.bit.GPIO13=1;
GpioDataRegs.GPADAT.bit.GPIO12=1;
for(delay=0;delay<2000000;delay++);
GpioDataRegs.GPADAT.bit.GPIO13=0;
GpioDataRegs.GPADAT.bit.GPIO12=0;
for(delay=0;delay<2000000;delay++);

}
}

Though this variant worked

#include "F28x_Project.h"
void main()
{uint32_t delay;
InitSysCtrl();
InitGpio();
EALLOW;
GpioCtrlRegs.GPADIR.bit.GPIO12=1;
GpioCtrlRegs.GPADIR.bit.GPIO13=1;
GpioCtrlRegs.GPAMUX1.bit.GPIO12=0;
GpioCtrlRegs.GPAMUX1.bit.GPIO13=0;
EDIS;


while(1)
{
GpioDataRegs.GPASET.bit.GPIO13=1;
GpioDataRegs.GPASET.bit.GPIO12=1;
for(delay=0;delay<2000000;delay++);
GpioDataRegs.GPACLEAR.bit.GPIO13=1;
GpioDataRegs.GPACLEAR.bit.GPIO12=1;
for(delay=0;delay<2000000;delay++);

}
}

why?

  • Deepak,

    Your question about the code has to do with the difference between using the GPADAT and GPASET/GPACLEAR registers. The issue you are running into with GPADAT has to do with the lag between when the register is written to and when the new pin value is reflected back in the register. This poses a problem when this register is used in subsequent program statements to alter the state of GPIO pins. One solution is to use some NOPs between the instructions, but a better solution is to use GPASET/GPACLEAR registers instead of the GPADAT register. This is explained in detail in the F2837xS Technical Reference Manual (SPRUHX5E) starting on page 787 under "6.3 Digital General-Purpose I/O control".

    I hope this answers your question and if so, please click the green "Verified Answer" button. Thank you.

    - Ken