Other Parts Discussed in Thread: TM4C123GH6PM
Hey guys, I'm trying to use TIMER0 to sample an ADC input pin every second. I've gone through the interrupt and ADC12 tuts from the workbook, but am having a bit of trouble combining them. Currently I get an ISR fault at ADCSequenceEnable. Any help appreciated.
#include <stdint.h>
#include <stdbool.h>
#include "inc/hw_types.h"
#include "driverlib/sysctl.h"
#include "inc/tm4c123gh6pm.h"
#include "driverlib/adc.h"
#include "driverlib/gpio.h"
#include "driverlib/debug.h"
#include "inc/hw_memmap.h"
#include "driverlib/timer.h"
#include "driverlib/interrupt.h"
uint32_t ADC0Values[1]; // global ADC value
int main(void) {
SysCtlClockSet(SYSCTL_SYSDIV_5|SYSCTL_USE_PLL|SYSCTL_OSC_MAIN|SYSCTL_XTAL_16MHZ); // 40 Mhz
// Timer Stuff
SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0);
TimerConfigure(TIMER0_BASE, TIMER_CFG_PERIODIC);
TimerLoadSet(TIMER0_BASE, TIMER_A, SysCtlClockGet()); // 1 Hz
TimerEnable(TIMER0_BASE, TIMER_A);
// ADC - setup channel 0 with SS3
SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0);
ADCSequenceDisable(ADC0_BASE, 3); // disable for config
ADCSequenceConfigure(ADC0_BASE, 3, ADC_TRIGGER_TIMER, 0);
ADCSequenceStepConfigure(ADC0_BASE,3,0, ADC_CTL_CH0|ADC_CTL_IE|ADC_CTL_END);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE);
GPIOPinTypeADC(GPIO_PORTE_BASE, GPIO_PIN_6); // E5 is input
SysCtlADCSpeedSet(SYSCTL_ADCSPEED_500KSPS);
ADCSequenceEnable(ADC0_BASE, 3);
ADCIntEnable(ADC0_BASE, 3);
TimerControlTrigger(TIMER0_BASE, TIMER_A, 1);
ADCIntClear(ADC0_BASE, 1);
ADCIntEnable(ADC0_BASE, 1);
IntEnable(INT_ADC0SS3); // interrupts on sequence 3
while(1) {
// NOP
}
}
void Timer0IntHandler(void) {
ADCIntClear(ADC0_BASE, 1);
ADCSequenceDataGet(ADC0_BASE, 3, ADC0Values);
ADCIntClear(ADC0_BASE, 1);
}