I'm hoping someone can take a look at my code and help me figure out why it's not working. I am trying to sample an analog audio signal through the on-board ADC. I can get a reading when I configure the ADC sequence with ADC_Trigger_Processor, but have been unable to get my code to work when I add a periodic timer and try to configure it using ADC_Trigger_Timer. As far as I can tell the interrupt just never happens. I am using the TivaWare Peripheral Driver Library functions. My lab instructor looked at my code and told me that everything looks correct, and he couldn't figure out why it's not working either. Here's my main code:
#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/interrupt.h" #include "inc/tm4c123gh6pm.h" #include "driverlib/gpio.h" #include "driverlib/timer.h" uint32_t ui32Sample; // GPIO initialization void GPIO_Init(void){ // // Enable Peripheral Clocks // SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE); // // Enable pin PE3 for ADC AIN0 // GPIOPinTypeADC(GPIO_PORTE_BASE, GPIO_PIN_3); } //ADC0 initializaiton void ADC0_Init(void) { SysCtlClockSet(SYSCTL_SYSDIV_5|SYSCTL_USE_PLL|SYSCTL_OSC_MAIN|SYSCTL_XTAL_16MHZ); // configure the system clock to be 40MHz SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0); //activate the clock of ADC0 SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0); //activate the clock of Timer0 SysCtlDelay(2); //insert a few cycles after enabling the peripheral to allow the clock to be fully activated. TimerConfigure(TIMER0_BASE, TIMER_CFG_PERIODIC); // configure Timer0 as periodic TimerLoadSet(TIMER0_BASE, TIMER_A, 10000); //load Timer0A with period of 10000 clock cycles //IntPrioritySet(INT_TIMER0A, 0x00); // configure Timer0A interrupt priority as 0 ADCSequenceDisable(ADC0_BASE, 3); //disable ADC0 before the configuration is complete ADCSequenceConfigure(ADC0_BASE, 3, ADC_TRIGGER_TIMER, 0); // will use ADC0, SS3, processor-trigger, priority 0 //ADC0 SS3 Step 0, sample from ADC SS3 channel 0, completion of this step will set RIS, last sample of the sequence ADCSequenceStepConfigure(ADC0_BASE,3,0,ADC_CTL_CH0|ADC_CTL_IE|ADC_CTL_END); IntPrioritySet(INT_ADC0SS3, 0x00); // configure ADC0 SS3 interrupt priority as 0 IntEnable(INT_ADC0SS3); // enable interrupt on ADC0 SS3 ADCIntEnableEx(ADC0_BASE, ADC_INT_SS3); // arm interrupt of ADC0 SS3 TimerControlTrigger(TIMER0_BASE, TIMER_A, true); // specifies trigger timer ADCSequenceEnable(ADC0_BASE, 3); //enable ADC0 } //interrupt handler void ADC0_Handler(void) { ADCIntClear(ADC0_BASE, 3); // clear the interrupt ADCSequenceDataGet(ADC0_BASE, 3, &ui32Sample); // collect sample data from PE3 } int main(void) { ADC0_Init(); // initialize ADC0 and Timer0 GPIO_Init(); // initialize gpio IntMasterEnable(); // globally enable interrupt while(1) { } }
and here's the part of my startup_rvmdk.s file that I've edited:
;****************************************************************************** ; ; External declarations for the interrupt handlers used by the application. ; ;****************************************************************************** EXTERN ADC0_Handler ;****************************************************************************** ; ; The vector table. ; ;****************************************************************************** EXPORT __Vectors __Vectors DCD StackMem + Stack ; Top of Stack DCD Reset_Handler ; Reset Handler DCD NmiSR ; NMI Handler DCD FaultISR ; Hard Fault Handler DCD IntDefaultHandler ; The MPU fault handler DCD IntDefaultHandler ; The bus fault handler DCD IntDefaultHandler ; The usage fault handler DCD 0 ; Reserved DCD 0 ; Reserved DCD 0 ; Reserved DCD 0 ; Reserved DCD IntDefaultHandler ; SVCall handler DCD IntDefaultHandler ; Debug monitor handler DCD 0 ; Reserved DCD IntDefaultHandler ; The PendSV handler DCD IntDefaultHandler ; The SysTick handler DCD IntDefaultHandler ; GPIO Port A DCD IntDefaultHandler ; GPIO Port B DCD IntDefaultHandler ; GPIO Port C DCD IntDefaultHandler ; GPIO Port D DCD IntDefaultHandler ; GPIO Port E DCD IntDefaultHandler ; UART0 Rx and Tx DCD IntDefaultHandler ; UART1 Rx and Tx DCD IntDefaultHandler ; SSI0 Rx and Tx DCD IntDefaultHandler ; I2C0 Master and Slave DCD IntDefaultHandler ; PWM Fault DCD IntDefaultHandler ; PWM Generator 0 DCD IntDefaultHandler ; PWM Generator 1 DCD IntDefaultHandler ; PWM Generator 2 DCD IntDefaultHandler ; Quadrature Encoder 0 DCD IntDefaultHandler ; ADC Sequence 0 DCD IntDefaultHandler ; ADC Sequence 1 DCD IntDefaultHandler ; ADC Sequence 2 DCD ADC0_Handler ; ADC Sequence 3 DCD IntDefaultHandler ; Watchdog timer DCD IntDefaultHandler ; Timer 0 subtimer A DCD IntDefaultHandler ; Timer 0 subtimer B DCD IntDefaultHandler ; Timer 1 subtimer A DCD IntDefaultHandler ; Timer 1 subtimer B DCD IntDefaultHandler ; Timer 2 subtimer A DCD IntDefaultHandler ; Timer 2 subtimer B DCD IntDefaultHandler ; Analog Comparator 0 DCD IntDefaultHandler ; Analog Comparator 1 DCD IntDefaultHandler ; Analog Comparator 2 DCD IntDefaultHandler ; System Control (PLL, OSC, BO) DCD IntDefaultHandler ; FLASH Control DCD IntDefaultHandler ; GPIO Port F DCD IntDefaultHandler ; GPIO Port G DCD IntDefaultHandler ; GPIO Port H DCD IntDefaultHandler ; UART2 Rx and Tx DCD IntDefaultHandler ; SSI1 Rx and Tx DCD IntDefaultHandler ; Timer 3 subtimer A DCD IntDefaultHandler ; Timer 3 subtimer B DCD IntDefaultHandler ; I2C1 Master and Slave DCD IntDefaultHandler ; Quadrature Encoder 1 DCD IntDefaultHandler ; CAN0 DCD IntDefaultHandler ; CAN1 DCD 0 ; Reserved DCD 0 ; Reserved DCD IntDefaultHandler ; Hibernate DCD IntDefaultHandler ; USB0 DCD IntDefaultHandler ; PWM Generator 3 DCD IntDefaultHandler ; uDMA Software Transfer DCD IntDefaultHandler ; uDMA Error DCD IntDefaultHandler ; ADC1 Sequence 0 DCD IntDefaultHandler ; ADC1 Sequence 1 DCD IntDefaultHandler ; ADC1 Sequence 2 DCD IntDefaultHandler ; ADC1 Sequence 3 DCD 0 ; Reserved DCD 0 ; Reserved DCD IntDefaultHandler ; GPIO Port J DCD IntDefaultHandler ; GPIO Port K DCD IntDefaultHandler ; GPIO Port L DCD IntDefaultHandler ; SSI2 Rx and Tx DCD IntDefaultHandler ; SSI3 Rx and Tx DCD IntDefaultHandler ; UART3 Rx and Tx DCD IntDefaultHandler ; UART4 Rx and Tx DCD IntDefaultHandler ; UART5 Rx and Tx DCD IntDefaultHandler ; UART6 Rx and Tx DCD IntDefaultHandler ; UART7 Rx and Tx DCD 0 ; Reserved DCD 0 ; Reserved DCD 0 ; Reserved DCD 0 ; Reserved DCD IntDefaultHandler ; I2C2 Master and Slave DCD IntDefaultHandler ; I2C3 Master and Slave DCD IntDefaultHandler ; Timer 4 subtimer A DCD IntDefaultHandler ; Timer 4 subtimer B DCD 0 ; Reserved DCD 0 ; Reserved DCD 0 ; Reserved DCD 0 ; Reserved DCD 0 ; Reserved DCD 0 ; Reserved DCD 0 ; Reserved DCD 0 ; Reserved DCD 0 ; Reserved DCD 0 ; Reserved DCD 0 ; Reserved DCD 0 ; Reserved DCD 0 ; Reserved DCD 0 ; Reserved DCD 0 ; Reserved DCD 0 ; Reserved DCD 0 ; Reserved DCD 0 ; Reserved DCD 0 ; Reserved DCD 0 ; Reserved DCD IntDefaultHandler ; Timer 5 subtimer A DCD IntDefaultHandler ; Timer 5 subtimer B DCD IntDefaultHandler ; Wide Timer 0 subtimer A DCD IntDefaultHandler ; Wide Timer 0 subtimer B DCD IntDefaultHandler ; Wide Timer 1 subtimer A DCD IntDefaultHandler ; Wide Timer 1 subtimer B DCD IntDefaultHandler ; Wide Timer 2 subtimer A DCD IntDefaultHandler ; Wide Timer 2 subtimer B DCD IntDefaultHandler ; Wide Timer 3 subtimer A DCD IntDefaultHandler ; Wide Timer 3 subtimer B DCD IntDefaultHandler ; Wide Timer 4 subtimer A DCD IntDefaultHandler ; Wide Timer 4 subtimer B DCD IntDefaultHandler ; Wide Timer 5 subtimer A DCD IntDefaultHandler ; Wide Timer 5 subtimer B DCD IntDefaultHandler ; FPU DCD 0 ; Reserved DCD 0 ; Reserved DCD IntDefaultHandler ; I2C4 Master and Slave DCD IntDefaultHandler ; I2C5 Master and Slave DCD IntDefaultHandler ; GPIO Port M DCD IntDefaultHandler ; GPIO Port N DCD IntDefaultHandler ; Quadrature Encoder 2 DCD 0 ; Reserved DCD 0 ; Reserved DCD IntDefaultHandler ; GPIO Port P (Summary or P0) DCD IntDefaultHandler ; GPIO Port P1 DCD IntDefaultHandler ; GPIO Port P2 DCD IntDefaultHandler ; GPIO Port P3 DCD IntDefaultHandler ; GPIO Port P4 DCD IntDefaultHandler ; GPIO Port P5 DCD IntDefaultHandler ; GPIO Port P6 DCD IntDefaultHandler ; GPIO Port P7 DCD IntDefaultHandler ; GPIO Port Q (Summary or Q0) DCD IntDefaultHandler ; GPIO Port Q1 DCD IntDefaultHandler ; GPIO Port Q2 DCD IntDefaultHandler ; GPIO Port Q3 DCD IntDefaultHandler ; GPIO Port Q4 DCD IntDefaultHandler ; GPIO Port Q5 DCD IntDefaultHandler ; GPIO Port Q6 DCD IntDefaultHandler ; GPIO Port Q7 DCD IntDefaultHandler ; GPIO Port R DCD IntDefaultHandler ; GPIO Port S DCD IntDefaultHandler ; PWM 1 Generator 0 DCD IntDefaultHandler ; PWM 1 Generator 1 DCD IntDefaultHandler ; PWM 1 Generator 2 DCD IntDefaultHandler ; PWM 1 Generator 3 DCD IntDefaultHandler ; PWM 1 Fault ;******************************************************************************
I don't know if it's important or not, but I'm using Kiel's uVision IDE and Stellaris IDCI debugger. Hopefully someone can take a look this and tell me if I'm missing something.