Below is the code that I am using to initialize, read the sensor, and call the function. Can somebody help me figure out why I am not getting any values from my sensor?
#include "C:/StellarisWare/inc/hw_memmap.h"
#include "C:/StellarisWare/inc/hw_types.h"
#include "C:/StellarisWare/driverlib/debug.h"
#include "C:/StellarisWare/driverlib/sysctl.h"
#include "C:/StellarisWare/driverlib/adc.h"
#include "C:/StellarisWare/driverlib/gpio.h"
#include "C:/StellarisWare/driverlib/pin_map.h"
#ifdef DEBUG
void__error__(char *pcFilename, unsigned long ulLine)
{
}
#endif
void initialize_sensor(){
SysCtlClockSet(SYSCTL_SYSDIV_5|SYSCTL_USE_PLL|SYSCTL_OSC_MAIN|SYSCTL_XTAL_16MHZ);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE);
SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0);
GPIOPinTypeADC(GPIO_PORTE_BASE, GPIO_PIN_5);
SysCtlADCSpeedSet(SYSCTL_ADCSPEED_250KSPS);
ADCSequenceDisable(ADC0_BASE, 0);
ADCSequenceConfigure(ADC0_BASE, 1, ADC_TRIGGER_PROCESSOR, 0);
ADCSequenceStepConfigure(ADC0_BASE, 0, 0, ADC_CTL_CH0);
ADCSequenceStepConfigure(ADC0_BASE, 0, 1, ADC_CTL_CH1);
ADCSequenceStepConfigure(ADC0_BASE, 0, 2, ADC_CTL_CH2);
ADCSequenceStepConfigure(ADC0_BASE, 0, 3, ADC_CTL_CH3 | ADC_CTL_IE | ADC_CTL_END);
ADCSequenceEnable(ADC0_BASE, 0);
}
int read_sensor_a() {
unsigned long value[4];
unsigned long new_value = 0;
int ad_value;
ADCIntClear(ADC0_BASE, 0);
ADCProcessorTrigger(ADC0_BASE, 0);
while(!ADCIntStatus(ADC0_BASE, 0, false))
{
ADCSequenceDataGet(ADC0_BASE, 0, value);
new_value = value[0] + value[1] + value[2] + value[3];
new_value = new_value/4;
ad_value = (int) new_value;
}
return ad_value;
}
int main(){
initialize_sensor();
for(;;){
int value = read_sensor_a();
}
}
Any help or suggestions would be greatly appreciated.