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.

Initializing a pin as input.

I am a beginner and learning program on my own. i was trying to configure my pin F4 as input. the code i am using is given below

#include <stdint.h>
#include <stdbool.h>
#include "inc/hw_memmap.h"
#include "inc/hw_gpio.h"
#include "inc/hw_types.h"
#include "driverlib/gpio.h"
#include "driverlib/sysctl.h"

void PortF_Init(void)
{
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);
HWREG(GPIO_PORTF_BASE+GPIO_O_LOCK)=GPIO_LOCK_KEY;
HWREG(GPIO_PORTF_BASE+GPIO_O_CR) = 0x01;
HWREG(GPIO_PORTF_BASE + GPIO_O_LOCK) = 0;

GPIODirModeSet(GPIO_PORTF_BASE,GPIO_PIN_2,GPIO_DIR_MODE_OUT);
GPIOPadConfigSet(GPIO_PORTF_BASE,GPIO_PIN_2,GPIO_STRENGTH_2MA,GPIO_PIN_TYPE_STD);

GPIODirModeSet(GPIO_PORTF_BASE,GPIO_PIN_0,GPIO_DIR_MODE_IN);
GPIOPadConfigSet(GPIO_PORTF_BASE,GPIO_PIN_0,GPIO_STRENGTH_4MA,GPIO_PIN_TYPE_STD_WPU);

}

int main()
{
uint32_t status;
PortF_Init();
while(1)
{
status=GPIOPinRead(GPIO_PORTF_BASE,GPIO_PIN_4);
if(status)
{
GPIOPinWrite(GPIO_PORTF_BASE,GPIO_PIN_2,0x0);
}
else
GPIOPinWrite(GPIO_PORTF_BASE,GPIO_PIN_2,0x4);
}
}

there are apparently no errors but the button is irresponsive to any change. this program just however turn on the LED. i appreciate any help.

  • Abdullah Zahid said:
    GPIODirModeSet(GPIO_PORTF_BASE,GPIO_PIN_0,GPIO_DIR_MODE_IN);
    status=GPIOPinRead(GPIO_PORTF_BASE,GPIO_PIN_4);

    trying to configure my pin F4 as input

     My friend - look at the 2 items in highlight, above.    Should not they agree - and comply with your introductory sentence?

    You may be able to reduce errors of this type by adding comments to the key/critical lines of your code.

    The fact thay you "detected" the (evil) lurking w/in PF0 is noted and commended...    (yet - PF0 (really) does not "come into play" in the description of your objective.)

    Our experience reveals that learning most always speeds & strengthens by your involvement in a local club, school or group.    (2nd set of eyes "finds" items I've "missed" for hours!...while delighting my (few) tormentors)

  • Hello Abdullah

    And may I add that while the following is correct functionally

    Abdullah Zahid said:
    status=GPIOPinRead(GPIO_PORTF_BASE,GPIO_PIN_4);
    if(status)

    Addition of further Input ports on GPIO Port F will cause this to misfire if any other pin is made high. May be you would not need to add further input ports, but if you do would save time when debugging.

    Regards

    Amit