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.

TMS320F280039C: Change GPIO direction during runtime

Part Number: TMS320F280039C


Dear Champs,

I am asking this for our customer.

The user wants to change a GPIO direction and value during runtime (in C28x ISR/background and in CLA tasks/background task8).

Would you please help confirm the considerations?

1. From GPIO input to output

In 10.3 Configuration Overview of TRM, it says in Step 4: Select the direction of any general-purpose I/O pins

"By default, all GPIO pins are inputs. Before changing a pin to an output, load the output latch with the value to be driven by writing that value to the GPySET, GPyCLEAR, or GPyDAT registers. Once the latch is loaded, write to GPyDIR to change the pin direction."

The user has to follow the sequence both in the GPIO initialization and runtime.

For example,

    GPIO_writePin(myGPIO0, 1);

    GPIO_setDirectionMode(myGPIO0, GPIO_DIR_MODE_OUT);

Is it correct?

2. From GPIO output to input,

The user can change the direction directly?

Is there any consideration like sequence here?

GPIO_setDirectionMode(myGPIO0, GPIO_DIR_MODE_IN);

  • Hi Wayne,

    Thanks for your questions.

    The user has to follow the sequence both in the GPIO initialization and runtime.

    For example,

        GPIO_writePin(myGPIO0, 1);

        GPIO_setDirectionMode(myGPIO0, GPIO_DIR_MODE_OUT);

    Is it correct?

    This is correct, but I recommend you also set the pad config too if needed (if you are needing to change it from whatever was set when it was in input mode). See gpio_ex1_setup.c for changing PadConfig:

        //
        // Enable a GPIO output on GPIO6, set it high
        //
        GPIO_setPadConfig(6, GPIO_PIN_TYPE_PULLUP);     // Enable pullup on GPIO6
        GPIO_writePin(6, 1);                            // Load output latch
        GPIO_setPinConfig(GPIO_6_GPIO6);                // GPIO6 = GPIO6
        GPIO_setDirectionMode(6, GPIO_DIR_MODE_OUT);    // GPIO6 = output

    2. From GPIO output to input,

    The user can change the direction directly?

    Is there any consideration like sequence here?

    I recommend you follow the gpio_ex1_setup.c sequence, modifying the pullup to whatever you desire the pin to be like, you don't need to setPinConfig if it's already set:

        // Make GPIO34 an input on GPIO34
        //
        GPIO_setPadConfig(34, GPIO_PIN_TYPE_PULLUP);     // Enable pullup on GPIO34
        GPIO_setPinConfig(GPIO_34_GPIO34);               // GPIO34 = GPIO34
        GPIO_setDirectionMode(34, GPIO_DIR_MODE_IN);     // GPIO34 = input

    If you don't want to change the PadConfig, then yes, you can just change the direction and that's it.

    Regards,

    Vince

  • Dear Vince,

    Thank you for your information.

    Initially, the user wanted to use CLA to change GPIO direction during runtime, but we just realize only CPU can access GPIO_CTRL_REGS Registers.

    CLA cannot access it.