I am trying to get Lab 5 from the Tiva launch pad workshop to work with interrupts. I am using a Stellaris launchpad. The idea of the lab was to just keep polling the ADCIntStatus until the sequencer was full and then process the values. However I wanted to try to have an interrupt tell me when sequencer was full. I am not sure if I have the interrupt set up correctly, or if I need to do sequencer different.
My code is below.
#include <stdint.h>
#include <stdbool.h>
#include "inc/hw_memmap.h"
#include "inc/hw_types.h"
#include "driverlib/debug.h"
#include "driverlib/sysctl.h"
#include "driverlib/adc.h"
#include "driverlib/gpio.h"
#define TARGET_IS_BLIZZARD_RB1
#include "driverlib/rom.h"
#include "driverlib/interrupt.h"
#ifdef DEBUG
void__error__(char *pcFilename, uint32_t ui32Line)
{
}
#endif
//used for storing data from ADC FIFO, must be as large as the FIFO for sequencer in use. Sequencer 1 has FIFO depth of 4
uint32_t ui32ADC0Value[4];
//variables that cannot be optimized out by compiler
volatile uint32_t ui32TempAvg;
volatile uint32_t ui32TempValueC;
volatile uint32_t ui32TempValueF;
volatile uint32_t status;
void ADC0IntHandler(void)
{
//clear interrupt flag
ROM_ADCIntClear(ADC0_BASE, 1);
ROM_ADCSequenceDataGet(ADC0_BASE,1,ui32ADC0Value);
//calculate average
ui32TempAvg = (ui32ADC0Value[0] + ui32ADC0Value[1] + ui32ADC0Value[2] + ui32ADC0Value[3] + 2)/4;
//TEMP = 147.5 – ((75 * (VREFP – VREFN) * ADCVALUE) / 4096) multiply by 10 to keep precision and then div by 10 at end
ui32TempValueC = (1475 - ((2475 * ui32TempAvg)) / 4096)/10;
ui32TempValueF = ((ui32TempValueC * 9) + 160) / 5;
}
int main(void)
{
//config sysClock to run at 40MHz
ROM_SysCtlClockSet(SYSCTL_SYSDIV_5|SYSCTL_USE_PLL|SYSCTL_XTAL_16MHZ|SYSCTL_OSC_MAIN);
//enable ADC0 peripheral
ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0);
//configure number of samples to be averaged
ROM_ADCHardwareOversampleConfigure(ADC0_BASE, 64);
//configure ADC sequencer - use ADC 0, sample sequencer 1, want the processor to trigger sequence, use highest priority
ROM_ADCSequenceConfigure(ADC0_BASE, 1, ADC_TRIGGER_PROCESSOR, 0);
//Configure ADC Sequencer Steps 0 - 2 on sequencer 1 to sample the temperature sensor
ROM_ADCSequenceStepConfigure(ADC0_BASE, 1, 0, ADC_CTL_TS);
ROM_ADCSequenceStepConfigure(ADC0_BASE, 1, 1, ADC_CTL_TS);
ROM_ADCSequenceStepConfigure(ADC0_BASE, 1, 2, ADC_CTL_TS);
//final sequencer step: need to sample temp sensor(ADC_CTL_TS), configure interrupt flag(ADC_CTL_IE) to be set when sample is done
//tell ADC logic that this is the last conversion on sequencer (ADC_CTL_END)
ROM_ADCSequenceStepConfigure(ADC0_BASE,1,3,ADC_CTL_TS|ADC_CTL_IE|ADC_CTL_END);
ROM_ADCSequenceEnable(ADC0_BASE,1);
//enable interrupt, may need to enable processor interrupt:
IntMasterEnable();
ADCIntClear(ADC0_BASE,1);
ADCIntEnable(ADC0_BASE,1);
//IntEnable(INT_ADC0); //This line isn't working either
//clear interrupt flag
ADCIntClear(ADC0_BASE, 1);
while(1)
{
//trigger ADC conversion
ROM_ADCProcessorTrigger(ADC0_BASE, 1);
volatile int32_t status = status = ADCIntStatus(ADC0_BASE,1,false);
}
}
Thank you for any help.