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/TMS320F28335: GPIO ENABLE DISABLE

Part Number: TMS320F28335

Tool/software: Code Composer Studio

Hi,
I have configured 4 ePWM modules to generate sine pwm which is working. I need to find out the program execution time. For this i want to set GPIO31 as high at the start of the program and move it to low at the end of the program.
I had tried to configure it as follows, which is not working
kindly point out where i am going wrong.

  • void main(void)
    {

    // Step 1. Initialize System Control:
    // PLL, WatchDog, enable Peripheral Clocks
    // This example function is found in the DSP2833x_SysCtrl.c file.
       InitSysCtrl();



       // my code for sine table//


    // Step 2. Initialize GPIO:
    // This example function is found in the DSP2833x_Gpio.c file and
    // illustrates how to set the GPIO to it's default state.
    //InitGpio();  // Skipped for this example
    EALLOW;
         //GpioCtrlRegs.GPAPUD.bit.GPIO31 = 0;   // Enable pullup on GPIO6
           // Load output latch
         GpioCtrlRegs.GPAMUX2.bit.GPIO31 = 0;  // GPIO6 = GPIO6
         GpioCtrlRegs.GPADIR.bit.GPIO31 = 1;   // GPIO6 = output
         GpioDataRegs.GPASET.bit.GPIO31 = 1;
    EDIS;

    // For this case just init GPIO pins for ePWM1, ePWM2, ePWM3
    // These functions are in the DSP2833x_EPwm.c file
       InitEPwm1Gpio();  //T1 CARRIER//
       InitEPwm2Gpio();  //T1 CARRIER//
       InitEPwm3Gpio();  //T2 CARRIER//
       InitEPwm4Gpio();  //T2 CARRIER//

    // Step 3. Clear all interrupts and initialize PIE vector table:
    // Disable CPU interrupts
       DINT;

    // Initialize the PIE control registers to their default state.
    // The default state is all PIE interrupts disabled and flags
    // are cleared.
    // This function is found in the DSP2833x_PieCtrl.c file.
       InitPieCtrl();

    // Disable CPU interrupts and clear all CPU interrupt flags:
       IER = 0x0000;
       IFR = 0x0000;

    // Initialize the PIE vector table with pointers to the shell Interrupt
    // Service Routines (ISR).
    // This will populate the entire table, even if the interrupt
    // is not used in this example.  This is useful for debug purposes.
    // The shell ISR routines are found in DSP2833x_DefaultIsr.c.
    // This function is found in DSP2833x_PieVect.c.
       InitPieVectTable();

    // Interrupts that are used in this example are re-mapped to
    // ISR functions found within this file.
       EALLOW;  // This is needed to write to EALLOW protected registers
        // This is needed to write to EALLOW protected registers



       PieVectTable.EPWM1_INT = &epwm_isr;
       PieVectTable.EPWM2_INT = &epwm_isr;
       PieVectTable.EPWM3_INT = &epwm_isr;
       PieVectTable.EPWM4_INT = &epwm_isr;
       EDIS;    // This is needed to disable write to EALLOW protected registers

    // Step 4. Initialize all the Device Peripherals:
    // This function is found in DSP2833x_InitPeripherals.c
    // InitPeripherals();  // Not required for this example

    // For this example, only initialize the ePWM

       EALLOW;
       SysCtrlRegs.PCLKCR0.bit.TBCLKSYNC = 0;
       EDIS;

       InitEPwm1Example();
       InitEPwm2Example();
       InitEPwm3Example();
       InitEPwm4Example();

       EALLOW;
       SysCtrlRegs.PCLKCR0.bit.TBCLKSYNC = 1;
       EDIS;


    // Step 5. User specific code, enable interrupts:

    // Enable CPU INT3 which is connected to EPWM1-3 INT:
       IER |= M_INT3;

    // Enable EPWM INTn in the PIE: Group 3 interrupt 1-3
       PieCtrlRegs.PIEIER3.bit.INTx1 = 1;
       PieCtrlRegs.PIEIER3.bit.INTx2 = 1;
       PieCtrlRegs.PIEIER3.bit.INTx3 = 1;
       PieCtrlRegs.PIEIER3.bit.INTx4 = 1;
    // Enable global Interrupts and higher priority real-time debug events:
       EINT;   // Enable Global interrupt INTM
       ERTM;   // Enable Global realtime interrupt DBGM

       //GpioDataRegs.GPACLEAR.bit.GPIO31 = 1;

    // Step 6. IDLE loop. Just sit and loop forever (optional):
       for(;;)
       {
           __asm("          NOP");
       }
    }

  • The line of code "GpioDataRegs.GPACLEAR.bit.GPIO31 = 1;" is commented out.

    Also I follow the same steps to make GPIO32 toggle in one of my tests. Can you single step over the GPIO Data regs clear and set instructions to make sure that it isn't actually setting/clearin?

    Here is what I do to make GPIO32 toggle.

        EALLOW;
        GpioCtrlRegs.GPBPUD.bit.GPIO32 = 1;    // Disable pull-up on GPIO32
        GpioCtrlRegs.GPBMUX1.bit.GPIO32 = 0;   // Configure GPIO
        GpioCtrlRegs.GPBGMUX1.bit.GPIO32 = 0;   // Configure GPIO
        GpioCtrlRegs.GPBDIR.bit.GPIO32 = 1; //Output
        EDIS;
        GpioDataRegs.GPBSET.bit.GPIO32 = 1;
        DELAY_US(3);
        GpioDataRegs.GPBCLEAR.bit.GPIO32 = 1;

  • Err.. This was commented out in the code because i was running it without gpio toggle. I want to set the gpio pin high at the start of the program and set it low at the end of the program execution. In your code above, what does DELAY_US(3) do
  • The code I provided is for GPIO32 and It sets the GPIO high for 3us and then low. Single step through the code to see if it goes high after the SET and low after CLEAR.

  • Have you tried this?