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.

Basic problem with GPIO stellaris launchpad



Hi,

my problem is banal, but I'm new with the stellaris.I set a pin as an Input. After this I set the same pin as an output. For now there's no problem I think, but if I set the pin as an input again, the MCU doesn't read: it reads the value that I write on the pin when it was set as output.

This is the code:

#define Data_Base GPIO_PORTE_BASE

#define Data_Pin   GPIO_PIN1

SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE);

GPIODirModeSet(Data_Base, Data_Pin,GPIO_DIR_MODE_IN);

value=GPIOPinRead(Data_Base, Data_Pin);

GPIODirModeSet(Data_Base, Data_Pin,GPIO_DIR_MODE_OUT);

GPIOPinWrite(Data_Base, Data_Pin, Data_Pin);

GPIODirModeSet(Data_Base, Data_Pin,GPIO_DIR_MODE_IN);

value=GPIOPinRead(Data_Base, Data_Pin);         //here I read what I have written

Where I wrong?

Thank you

  • Hello,

    I'm sorry I did not see the "launchpad" in the title.

    Is anything connected to this pin on your launchpad?

    Did you try writing a "0" to that port and did you read back a "0" as well? 

    Is it possible the optimizations of your tool chain (compiler) is optimizing out the last read since "value" may not be used in the rest of your code?

    Regards,

    Dan

  • Hi,

    there is nothing connected to the pin.

    With the code of the previous post, I try all the combination IN-OUT-IN.

    Now I have rewritten the code, changing GPIODirModeSet(...in/out) with GPIOPinTypeGPIOInput/Output and it seems working.

    What is the difference between these two instructions?

    Thank you

  • If there's nothing connected to the pin and it's just floating, I would expect the behavior you are seeing. If you drive the pin in a given direction then immediately switch it to an input and read it back, you'll read an indeterminate value but most likely the same as you last wrote since the pin was last driven to a valid logic state and the voltage is probably slowly decaying back to some central, floating level. If you have a pull-up or pull-down on the pin, I would expect your code to read back the pulled-up or pulled-down state of the pin after you switch it back to an input.

  • i have the same problem 
    when i set this output pin , then read it ,
    Readpin function return 64
    and when clear this pin , the read pin function return 0

  • Hello Ibrahem

    In output mode the read function reads the value of the data register.

    Regards
    Amit