Other Parts Discussed in Thread: EK-TM4C123GXL
Tool/software: TI-RTOS
Hello,
I have some questions about how to run a function after triggering a GPIO interrupt. I have gone through the GPIO interrupt example and I had some issues modifying it to work with what I want to do.
- Task: Measure the time it takes for a GPIO to go from "high" to "low". When GPIO is "low", trigger an interrupt to runs a function that records that time (in ticks) down.
Below is what I wrote in order to achieve to task above. The code was able to run but immediately exited (infinite while loop doing nothing). I was hoping if someone could explain to me where I went wrong and how to address it.
=====Code======
int main (void)
{
//assume all peripherals and basic initial functions have been called
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF); //setup
GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_4); //set to output to drive pin high later
/* My sensor to connected to PF4 and I want it to flag an interrupt when it detects a "low" in the pin */
GPIOIntTypeSet(GPIO_PORTF_BASE, GPIO_PIN_4, GPIO_LOW_LEVEL);
/* Tells RTOS which function to go to when interrupt occurs, I think this where I am having issues since the first parameter should be an int index number in an array */
GPIO_setCallback(GPIO_PIN_4, lightSensorCalculation);
/* Enable interrupts; same issue here */
GPIO_enableInt(GPIO_PIN_4);
GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_4, 0x00000010); //set pin to high (I think, but was not able to verify in datasheet)
SysTickPeriodSet(1000); //setup for "tick counter"
SysTickEnable();
SysCtlDelay(100); //delay to give GPIO time to be set to high
GPIOPinTypeGPIOInput(GPIO_PORTF_BASE, GPIO_PIN_4); //now set to read the pin
/* Start BIOS */
BIOS_start();
}
/* I want this function to run when interrupt is triggered when the GPIO detects a "low" */
void lightSensorCalculation(void)
{
uint32_t lightSensorValue = 0;
lightSensorValue = SysTickValueGet(); //get number of ticks since setting GPIO to high
UARTprintf("%d\n", lightSensorValue); //print to PuTTy
HWREG(NVIC_ST_CURRENT) = 1; //reset tick count
SysTickDisable(); //disable tick function to prevent it from counting again
}
===End of Code===
I have also attached my entire file for those that want to see everything. Thank you in advance for your help.
/cfs-file/__key/communityserver-discussions-components-files/908/light_5F00_sensor_5F00_demo.txt