Part Number: TM4C1294NCPDT
Tool/software: Code Composer Studio
I am using Tiva C TM4C1294 connected launchpad to read ADC data from a sensor. I am sampling the ADC using timer interrupt. My code is shown below. In this program, I want the index of the array read_data to go to 0 once the whole of it is filled and the ADC should continuously fill new data to the array but if(i==99) condition does not execute and read_data array does not continuously get updated instead it remains the same after the first 100 fillings. Please, if someone can let me know where I am going wrong.
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include "inc/hw_ints.h"
#include "inc/hw_memmap.h"
#include "driverlib/interrupt.h"
#include "driverlib/adc.h"
#include "driverlib/gpio.h"
#include "driverlib/pin_map.h"
#include "driverlib/sysctl.h"
#include "driverlib/timer.h"
uint32_t pui32ADC0Value[1];
uint32_t read_data[100];
uint16_t i = 0
int
main(void)
{
uint32_t ui32SysClock;
ui32SysClock = SysCtlClockFreqSet((SYSCTL_XTAL_25MHZ |
SYSCTL_OSC_MAIN |
SYSCTL_USE_PLL |
SYSCTL_CFG_VCO_480), 120000000);
SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0);
SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE);
GPIOPinTypeADC(GPIO_PORTE_BASE, GPIO_PIN_3);
ADCSequenceConfigure(ADC0_BASE, 3, ADC_TRIGGER_PROCESSOR, 0);
TimerConfigure(TIMER0_BASE, TIMER_CFG_SPLIT_PAIR | TIMER_CFG_B_PERIODIC);
ADCSequenceStepConfigure(ADC0_BASE, 3, 0, ADC_CTL_CH0 | ADC_CTL_IE |
ADC_CTL_END);
TimerLoadSet(TIMER0_BASE, TIMER_B, ui32SysClock / 1000);
IntMasterEnable();
TimerIntEnable(TIMER0_BASE, TIMER_TIMB_TIMEOUT);
IntEnable(INT_TIMER0B);
ADCSequenceEnable(ADC0_BASE, 3);
ADCIntClear(ADC0_BASE, 3);
TimerEnable(TIMER0_BASE, TIMER_B);
while(1)
{
if(i==99){
i=0;
}
}
}
void
Timer0BIntHandler(void)
{
TimerIntClear(TIMER0_BASE, TIMER_TIMB_TIMEOUT);
ADCProcessorTrigger(ADC0_BASE, 3);
while(!ADCIntStatus(ADC0_BASE, 3, false))
{
}
ADCIntClear(ADC0_BASE, 3);
ADCSequenceDataGet(ADC0_BASE, 3, pui32ADC0Value);
read_data[i]=pui32ADC0Value[0];
i++;
}