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.

Reading PE1 in Tiva-C Launchpad



Dear all,

I want to read the input status of pin PE1 and I have the following code with TivaWare:

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

uint8_t ui8PinData = 2;
int32_t i32Val = 0x0;
int main(void) {
SysCtlClockSet(SYSCTL_SYSDIV_5|SYSCTL_USE_PLL|SYSCTL_XTAL_16MHZ|SYSCTL_OSC_MAIN);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE);
GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3);
GPIOPinTypeGPIOInput(GPIO_PORTE_BASE, GPIO_PIN_1);
SysCtlDelay(2000000);

while(1)
{
i32Val = GPIOPinRead(GPIO_PORTE_BASE,GPIO_PIN_1);

SysCtlDelay(2000000);
}

}

I have connected the pin PE1 to a pushbutton that shorts PE1 to ground when pressed. Now after running the program and putting a breakpoint at the line "i32Val = GPIOPinRead(GPIO_PORTE_BASE,GPIO_PIN_1);" , the value of i32Val doesnot become 0x00000000 even when the switch is pressed. Are there any other initializations required for reading the input?

  • Hello Turjasu,

    The code is fine. If the push button has a Pull Up when it is not pressed the i32Val should read 0x2 and when the button is pressed so that the pin gets connected to GND then it should read 0x0.

    Can you define the variable as volatile int32_t instead of int32_t and try?

    On the HW side can you check the offset of 0x3FC in the GPIO_PORTE_BASE the value of the register when the button is pressed and when it is not?

    If nothing else works, make the pin as output and toggle it 1 0 to see if the Pin is alive and well connected?

    Regards

    Amit

  • TURJASU PYNE1 said:
    putting a breakpoint at the line "i32Val = GPIOPinRead(GPIO_PORTE_BASE,GPIO_PIN_1);" , the value of i32Val doesnot become 0x00000000 even when the switch is pressed.

    Suspect that you use CCS (we use IAR) and when we "break" at a specific line - the code stops prior to executing the code upon that line!  So - we insert a dummy code line immediately following any code line of interest - and instead - place our break point at that (following) line.

    As Amit notes - PE1 will not "automatically" see a logic "high" w/out either internal or external pull-up R to 3V3.  And we note that you state that PE1 is not read as, "0x00" yet you don't reveal what it is read as!  (we bet upon 0x02...)

  • Thanks to both of you. It worked fine. Thanks a lot for the help 

  • Hello Turjasu

    Might you want to post what the resolution of the issue was?

    Regards

    Amit

  • Dear Amit,

     It was the pull-up issue as you pointed out. Thanks

    Regards,

    Turjasu