Hi,
I have been using Tiva launchpad for a while. I tried to use the switch already present in the launchpad for making the LED turn ON. This is the code which I used.
#include <stdint.h>
#include <stdbool.h>
#include "inc/hw_memmap.h"
#include "inc/hw_types.h"
#include "driverlib/sysctl.h"
#include "driverlib/gpio.h"
int main(void)
{
SysCtlClockSet(SYSCTL_SYSDIV_10|SYSCTL_USE_PLL|SYSCTL_XTAL_16MHZ|SYSCTL_OSC_MAIN);
uint32_t PinData;
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);
GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3);
GPIOPinTypeGPIOInput(GPIO_PORTF_BASE, GPIO_PIN_0);
while(1)
{
PinData = GPIOPinRead(GPIO_PORTF_BASE, GPIO_PIN_0);
if( (PinData == GPIO_PIN_0))
GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3,0x00);
else
GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3,0xFF);
}
}
But when I run this code, the LED just turns ON and never turns OFF even if I press any of the switch. Is there any mistake in the code ? Moreover, when I measured the voltage on the pin PF0, I got 1.67 V when in idle state and 0 V when in pressed state. Are these the correct voltage levels ?
Thanks in advance