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.

Getting GPIO status in TMS320F28027

Hi,

 I am using below instruction to get the status of the GPIO_Number_3. I am not getting the status of 1 when I the input is high and 0 when the GPIO input is low. Please support me.

if(GPIO_getData(myGpio, GPIO_Number_3) == 1)

                     {

                   Setting();

                     }

                   else if (GPIO_getData(myGpio, GPIO_Number_3) == 0)

                     {

                     Monitoring();

                     }

Regards,

Mahesh K.R.

  • Hi Mahesh,

    There seems to be issue with the GPIO initialization. Have you initialized GPIO3 as input?

    Can you please attach your code for scrutiny?

    Regards,

    Gautam

  • Hi Gautam,

      Please see below.

    void InitGPIO()

    {

     

             GPIO_setMode(myGpio, GPIO_Number_0, GPIO_0_Mode_EPWM1A);

             GPIO_setMode(myGpio, GPIO_Number_1, GPIO_1_Mode_EPWM1B);

             GPIO_setMode(myGpio, GPIO_Number_2, GPIO_2_Mode_EPWM2A);

     

                         GPIO_setMode(myGpio, GPIO_Number_3, GPIO_3_Mode_GeneralPurpose);

                         GPIO_setMode(myGpio, GPIO_Number_28, GPIO_0_Mode_GeneralPurpose);

                         GPIO_setMode(myGpio, GPIO_Number_29, GPIO_0_Mode_GeneralPurpose);

                         GPIO_setMode(myGpio, GPIO_Number_4, GPIO_0_Mode_GeneralPurpose);

                         GPIO_setMode(myGpio, GPIO_Number_5, GPIO_0_Mode_GeneralPurpose);

                         GPIO_setMode(myGpio, GPIO_Number_6, GPIO_0_Mode_GeneralPurpose);

                         GPIO_setMode(myGpio, GPIO_Number_7, GPIO_0_Mode_GeneralPurpose);

                         GPIO_setMode(myGpio, GPIO_Number_12, GPIO_0_Mode_GeneralPurpose);

                         GPIO_setMode(myGpio, GPIO_Number_19, GPIO_0_Mode_GeneralPurpose);

                         GPIO_setMode(myGpio, GPIO_Number_34, GPIO_0_Mode_GeneralPurpose);

                         GPIO_setMode(myGpio, GPIO_Number_18, GPIO_0_Mode_GeneralPurpose);

     

     

     

             GPIO_setPullUp(myGpio, GPIO_Number_0, GPIO_PullUp_Disable);

             GPIO_setPullUp(myGpio, GPIO_Number_1, GPIO_PullUp_Disable);

             GPIO_setPullUp(myGpio, GPIO_Number_2, GPIO_PullUp_Disable);

     

                   GPIO_setDirection(myGpio, GPIO_Number_3, GPIO_Direction_Input);

                GPIO_setDirection(myGpio, GPIO_Number_28, GPIO_Direction_Output);

                GPIO_setDirection(myGpio, GPIO_Number_29, GPIO_Direction_Output);

                GPIO_setDirection(myGpio, GPIO_Number_4, GPIO_Direction_Output);

                GPIO_setDirection(myGpio, GPIO_Number_5, GPIO_Direction_Output);

                GPIO_setDirection(myGpio, GPIO_Number_6, GPIO_Direction_Output);

                GPIO_setDirection(myGpio, GPIO_Number_7, GPIO_Direction_Output);

                GPIO_setDirection(myGpio, GPIO_Number_12, GPIO_Direction_Output);

                GPIO_setDirection(myGpio, GPIO_Number_19, GPIO_Direction_Output);

                GPIO_setDirection(myGpio, GPIO_Number_34, GPIO_Direction_Output);

                GPIO_setDirection(myGpio, GPIO_Number_18, GPIO_Direction_Output);

     

     

     

                GPIO_setLow(myGpio, GPIO_Number_28);

                GPIO_setLow(myGpio, GPIO_Number_29);

                GPIO_setLow(myGpio, GPIO_Number_4);

                GPIO_setLow(myGpio, GPIO_Number_5);

                GPIO_setLow(myGpio, GPIO_Number_6);

                GPIO_setLow(myGpio, GPIO_Number_7);

                GPIO_setLow(myGpio, GPIO_Number_12);

                GPIO_setLow(myGpio, GPIO_Number_19);

                GPIO_setLow(myGpio, GPIO_Number_34);

                GPIO_setLow(myGpio, GPIO_Number_18);

     

    }

    I want to know the syntax and usage of the GPIO_getdata given below is correct or not. 

    if(GPIO_getData(myGpio, GPIO_Number_3) == 1)

                         {

                       Setting();

                         }

                       else if (GPIO_getData(myGpio, GPIO_Number_3) == 0)

                         {

                         Monitoring();

                         }

    Regards,

    Mahesh K.R.

     

     

     

  • Hi,

    For a button press this is how the scanning is done:

      while(GPIO_getData(myGpio, GPIO_Number_12) != 1)

    The way you've implemented seems to be fine.

    Regards,

    Gautam

  • Hi Gautam,

      Thanks for that. Let me try and see the result. I will come back to you tomorrow.

    Regards,

    Mahesh K.R.

  • Hi Gautam,

        The issue was the reverse logic in the switch not the code. It is working now. Thank you very much for the support.

    Regards,

    Mahesh K.R.

  • Gr8 to know and Congrats!

    Cheers,

    Gautam