Other Parts Discussed in Thread: EK-TM4C1294XL
Tool/software: Code Composer Studio
I'm using the CryptoConnected Launchpad with the TM4C129E, CCS Studio v6.2, driverlib from TivaWare.
I'm trying to use the ADC0, with TIMER0 being responsible for triggering conversion.
On the following code, TIMER1 interrupts every 3 seconds approx. normally, toggling a LED on the board. TIMER0 is configured to trigger the ADC0 on timeout.
However, it is not working properly. Sometimes the interrupt happens, it reaches a breakpoint i've set inside the ISR, and the conversion reading is ok, plus it keeps working until I close CCS or reboot my PC. But most of the times it doesn't work, the program stays on the infinite loop waiting for the interrupt and it never occurs. I've already looked on the register map and everything seems to be ok on the NVIC and on the Timer Regs.
I don't have any idea where the problem may be.
/* * ISRs */ void ISR_Timer1A() { TimerIntClear(TIMER1_BASE, TIMER_TIMA_TIMEOUT); if (led3s == 0) { GPIOPinWrite(GPIO_PORTN_BASE, GPIO_PIN_0, GPIO_PIN_0); GPIOPinWrite(GPIO_PORTN_BASE, GPIO_PIN_2, GPIO_PIN_2); led3s = 1; } else { led3s = 0; GPIOPinWrite(GPIO_PORTN_BASE, GPIO_PIN_0, 0); GPIOPinWrite(GPIO_PORTN_BASE, GPIO_PIN_2, 0); } return; } void ISR_ADC0() { ADCIntClear(ADC0_BASE, 3); while(ADCBusy(ADC0_BASE)); ADCSequenceDataGet(ADC0_BASE, 3, bufferTemp); if (ledConv == 0) { GPIOPinWrite(GPIO_PORTN_BASE, GPIO_PIN_1, GPIO_PIN_1); GPIOPinWrite(GPIO_PORTN_BASE, GPIO_PIN_3, GPIO_PIN_3); ledConv = 1; } else { ledConv = 0; GPIOPinWrite(GPIO_PORTN_BASE, GPIO_PIN_1, 0); GPIOPinWrite(GPIO_PORTN_BASE, GPIO_PIN_3, 0); } return; } /* * Main Loop */ int main(void) { led3s = 0; ledConv = 0; SysCtlClockFreqSet((SYSCTL_USE_OSC | SYSCTL_OSC_INT | SYSCTL_MAIN_OSC_DIS | SYSCTL_SYSDIV_1), 16000000); SysCtlPeripheralPowerOn(SYSCTL_PERIPH_GPIOE); SysCtlPeripheralPowerOn(SYSCTL_PERIPH_GPION); SysCtlPeripheralPowerOn(SYSCTL_PERIPH_TIMER0); SysCtlPeripheralPowerOn(SYSCTL_PERIPH_TIMER1); SysCtlPeripheralPowerOn(SYSCTL_PERIPH_ADC0); SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE); SysCtlPeripheralEnable(SYSCTL_PERIPH_GPION); while (!SysCtlPeripheralReady(SYSCTL_PERIPH_GPION)); GPIOPinTypeGPIOOutput(GPIO_PORTN_BASE, GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_2 | GPIO_PIN_3); GPIOPinTypeADC(GPIO_PORTE_BASE, GPIO_PIN_5); SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0); while (!SysCtlPeripheralReady(SYSCTL_PERIPH_ADC0)); ADCClockConfigSet(ADC0_BASE, (ADC_CLOCK_SRC_PIOSC | ADC_CLOCK_RATE_HALF), 1); ADCPhaseDelaySet(ADC0_BASE, ADC_PHASE_0); ADCReferenceSet(ADC0_BASE, ADC_REF_INT); ADCHardwareOversampleConfigure(ADC0_BASE, 64); ADCSequenceDisable(ADC0_BASE, 3); ADCSequenceConfigure(ADC0_BASE, 3, ADC_TRIGGER_PROCESSOR, 0); ADCSequenceStepConfigure(ADC0_BASE, 3, 0, (ADC_CTL_IE | ADC_CTL_END | ADC_CTL_SHOLD_8 | ADC_CTL_CH8)); SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0); while (!SysCtlPeripheralReady(SYSCTL_PERIPH_TIMER0)); TimerConfigure(TIMER0_BASE, TIMER_CFG_A_PERIODIC_UP); TimerUpdateMode(TIMER0_BASE, TIMER_A, TIMER_UP_LOAD_IMMEDIATE); TimerClockSourceSet(TIMER0_BASE, TIMER_CLOCK_SYSTEM); TimerLoadSet(TIMER0_BASE, TIMER_A, 1100); TimerADCEventSet(TIMER0_BASE, TIMER_ADC_TIMEOUT_A); TimerControlTrigger(TIMER0_BASE, TIMER_A, true); SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER1); while (!SysCtlPeripheralReady(SYSCTL_PERIPH_TIMER1)); TimerConfigure(TIMER1_BASE, TIMER_CFG_A_PERIODIC_UP); TimerUpdateMode(TIMER1_BASE, TIMER_A, TIMER_UP_LOAD_IMMEDIATE); TimerClockSourceSet(TIMER1_BASE, TIMER_CLOCK_SYSTEM); TimerLoadSet(TIMER1_BASE, TIMER_A, 48484848); ADCIntRegister(ADC0_BASE, 3, *ISR_ADC0); ADCIntClear(ADC0_BASE, 3); ADCIntEnableEx(ADC0_BASE, ADC_INT_SS3); IntEnable(INT_ADC0SS3); ADCIntEnable(ADC0_BASE, 3); ADCSequenceEnable(ADC0_BASE, 3); TimerIntRegister(TIMER1_BASE, TIMER_A, *ISR_Timer1A); TimerIntEnable(TIMER1_BASE, TIMER_TIMA_TIMEOUT); IntMasterEnable(); TimerEnable(TIMER0_BASE, TIMER_A); TimerEnable(TIMER1_BASE, TIMER_A); while (1) { } return 0; }
Thanks