Part Number: EK-TM4C123GXL
Other Parts Discussed in Thread: TM4C123GH6PM
Hello,
i am trying to make a simple program with the following funcionality:
Have periodic timer > It triggers and ADC sequence after sampling is done > after sampling is done ADC0 Sequence 0 ISR is called.
The idea is to use it later for control applications and entering the interrupt where the control law will be implemented periodically and with the sampling already done. I know that it will be simpler to just having a periodic interrupt and using the processor trigger for the ADC from there, but i think that it would be nicer entering the interruput with sampling already done.
From the debug screen i can see that the FIFO 0 from the ADC0 is being updated and also the register ADC_RIS is set to 1. This indicates to me that sampling is being done and that the ISR flag is being set in the registers, however my code never enters the Interrupt handler.
Let me know if you detect something wrong or something is missing with my code that may cause this to happen. Also im a kind of new to C and embedded programming, only experience with arduinos, so any comments with my coding style will be also very much appriciated.
I wont put the startup.c code, to not make the post any longer, but the interrupt is declared as an extern function and also in the ADC sequence0 line.
#include <stdint.h>
#include <stdbool.h>
#include "inc/tm4c123gh6pm.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 "driverlib/gpio.h"
#include "driverlib/timer.h"
volatile uint32_t ui32VoltageRead[8];
volatile float Voltage;
int main(void){
uint32_t ui32TimerLoad;
SysCtlClockSet(SYSCTL_SYSDIV_2_5|SYSCTL_USE_PLL|SYSCTL_OSC_MAIN|SYSCTL_XTAL_16MHZ);
SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0);
SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE);
TimerConfigure(TIMER0_BASE, TIMER_CFG_PERIODIC);
TimerADCEventSet(TIMER0_BASE, TIMER_ADC_TIMEOUT_A);
TimerControlTrigger(TIMER0_BASE,TIMER_A,true);
ui32TimerLoad = (SysCtlClockGet() / 15000);
TimerLoadSet(TIMER0_BASE, TIMER_A, ui32TimerLoad -1);
GPIOPinTypeADC(GPIO_PORTE_BASE,GPIO_PIN_3);
ADCHardwareOversampleConfigure(ADC0_BASE, 8);
ADCSequenceConfigure(ADC0_BASE, 0, ADC_TRIGGER_TIMER, 0);
ADCSequenceStepConfigure(ADC0_BASE, 0, 0, ADC_CTL_CH0|ADC_CTL_IE|ADC_CTL_END);
ADCSequenceEnable(ADC0_BASE, 0);
GPIOPinTypeGPIOOutput(GPIO_PORTE_BASE, GPIO_PIN_1);
ADCIntEnable(ADC0_BASE,0);
IntMasterEnable();
TimerEnable(TIMER0_BASE, TIMER_A);
GPIOPinWrite(GPIO_PORTE_BASE, GPIO_PIN_1, 0);
while(1){
SysCtlDelay(2000000);
GPIOPinWrite(GPIO_PORTE_BASE, GPIO_PIN_1, 2);
SysCtlDelay(2000000);
GPIOPinWrite(GPIO_PORTE_BASE, GPIO_PIN_1, 0);
}
}
void ADC0Sequence0IntHandler(void){
ADCIntClear(ADC0_BASE, 0);
ADCSequenceDataGet(ADC0_BASE, 1, ui32VoltageRead);
Voltage = (ui32VoltageRead[1]/4095.0)*3.3;
}
the code i have added to tm4c123gh6pm_startup_ccs.c in bold:
extern void ADC0Sequence0IntHandler(void);
and
IntDefaultHandler, // Quadrature Encoder 0
ADC0Sequence0IntHandler, // ADC Sequence 0
IntDefaultHandler, // ADC Sequence 1