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/TMS320F28377D: Function: Uint16 GPIO_ReadPin(Uint16 pin)

Part Number: TMS320F28377D


Tool/software: Code Composer Studio

Hi,

I am confused about the function of  Uint16 GPIO_ReadPin(Uint16 pin).

The following code is in the infinite loop and I am using GPIO_ReadPin(119).

The result is very strange. I use scope to measure the waveform of GPIO119 and it is low all the time.

However my  SYS_flag sometimes is 2 and sometimes I got sys_err = 2.  This means when GPIO_ReadPin(119) is read first time, GPIO_ReadPin(119)=0, then GPIO_ReadPin(119)=1 the second time and sometimes GPIO_ReadPin(119)=0 again the third time.

Why GPIO_ReadPin(119) can't be the same value all the time?  What is the return value of GPIO_ReadPin(119) except 0, 1?      -Thanks!

main ()

{

……

for (;;)

{

if (SYS_flag == 0)            

   {

     if (GPIO_ReadPin(119)== 0)

          SYS_flag = 1;

     else

       {       

          if (GPIO_ReadPin(119) != 0)

            sys_err = 1;

     }

if (SYS_flag == 1)

{

   if (GPIO_ReadPin(119)!= 0)

    SYS_flag = 2;

}

if (SYS_flag == 2)

{

   if (GPIO_ReadPin(119)!= 0)

    sys_err = 2;

}

 

}          

}

}

 

  • Hi,

    As mentioned in the comment section of GPIO_ReadPin:

    //
    // GPIO_ReadPin - Read the GPyDAT register bit for the specified pin. Note that
    //                this returns the actual state of the pin, not the state of
    //                the output latch.
    //

    Hence, you are getting a constant value on your output latch(probe) but the actual state of the pin might vary due to some delays. Please note, that you must use GPIO either as an input pin or an output pin. If you are probing a pin configured as output pin, then reading the pin value might give you a different value. 

    You can read more about this on TRM Page 908

    Ritvik

  • Thanks, Ritvik,

    I set it as input pin like this. Is this right?
    EALLOW;
    GPIO_SetupPinOptions(119, GPIO_INPUT, GPIO_PUSHPULL);
    EDIS;
    and then use the function of (GPIO_ReadPin(119).

    I got the waveform of GPIO119 using scope and it is low (120mV). And I observed it in the debug widow and it is 1 sometimes and 0 sometimes.
  • Hi Honmei,

    Hongmei Wan said:
    GPIO_SetupPinOptions(119, GPIO_INPUT, GPIO_PUSHPULL);

    1. By GPIO_PUSHPULL, I believe you mean GPIO_PULLUP? Please check this once.
    2. With this configuration, the GPIO pin 119 is in the input mode. So anything attached to the input pin will act as an input source.

    Hongmei Wan said:
    I got the waveform of GPIO119 using scope

    Since you have set the pin as an input pin, you must not probe the pin using a scope(you are using an oscilloscope I believe). Any residual voltage on the scope will result in a change in the values of the register. That is why you are getting different values in debug window (and in your code as well). Instead, you should use a signal generator to give a constant input and then check the state of the pin. Make sure you do not exceed the given current limit.

    Ritvik

  • Hi,
    Did the above answer solve your issue? If yes, then please mark it as Resolved. If there is anything else that you are not able to understand, please do reply back.
    Thanks
    Ritvik