Tool/software: Code Composer Studio
Hello! I'm quite new using this plataform and i'm having problems on using a timmer triggered ADC convertion. Can someone help me to find out what is wrong in my code?
//Inclusão de Arquivos/Bibliotecas #include <stdio.h> #include <stdlib.h> #include <stdint.h> #include <stdbool.h> #include "inc/hw_types.h" #include "inc/hw_memmap.h" #include "inc/hw_ints.h" #include "driverlib/adc.h" #include "driverlib/gpio.h" #include "driverlib/interrupt.h" #include "driverlib/pin_map.h" #include "driverlib/sysctl.h" #include "driverlib/uart.h" #include "utils/uartstdio.h" #include "driverlib/timer.h" static uint32_t ADC0Value[1]; static int var = 1; static int cont = 0; void InitConsole(void) { SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA); GPIOPinConfigure(GPIO_PA0_U0RX); GPIOPinConfigure(GPIO_PA1_U0TX); SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0); UARTClockSourceSet(UART0_BASE, UART_CLOCK_PIOSC); GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1); UARTStdioConfig(0, 115200, 16000000); } void InitADC(void) { SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0); SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE); while(!SysCtlPeripheralReady(SYSCTL_PERIPH_GPIOE)) { } GPIOPinTypeADC(GPIO_PORTE_BASE, GPIO_PIN_3 | GPIO_PIN_2); SysCtlDelay(80u); ADCClockConfigSet(ADC0_BASE, ADC_CLOCK_SRC_PLL | ADC_CLOCK_RATE_FULL, 5); SysCtlDelay(10u); IntDisable(INT_ADC0SS0); ADCIntDisable(ADC0_BASE, 3); ADCSequenceDisable(ADC0_BASE, 3); ADCSequenceConfigure(ADC0_BASE, 3, ADC_TRIGGER_TIMER, 0); ADCSequenceStepConfigure(ADC0_BASE, 3, 0, ADC_CTL_CH0 | ADC_CTL_IE | ADC_CTL_END); ADCIntClear(ADC0_BASE, 3); IntEnable(INT_ADC0SS3); ADCIntEnable(ADC0_BASE, 3); ADCSequenceEnable(ADC0_BASE, 3); } void InitGPIO(void) { SysCtlPeripheralEnable(SYSCTL_PERIPH_GPION); while(!SysCtlPeripheralReady(SYSCTL_PERIPH_GPION)) { } GPIOPinTypeGPIOOutput(GPIO_PORTN_BASE, GPIO_PIN_0 | GPIO_PIN_1); GPIOPinWrite(GPIO_PORTN_BASE, GPIO_PIN_0 | GPIO_PIN_1, 0X03); } void InitTimer0 (void) { SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0); TimerConfigure(TIMER0_BASE, TIMER_CFG_SPLIT_PAIR | TIMER_CFG_B_PERIODIC); TimerLoadSet(TIMER0_BASE, TIMER_B, SysCtlClockGet() / 1000); TimerControlTrigger(TIMER0_BASE, TIMER_B, true); TimerIntEnable(TIMER0_BASE, TIMER_TIMB_TIMEOUT); IntMasterEnable(); TimerEnable(TIMER0_BASE, TIMER_B); } void ADC0SS3IntHandler(void) { cont+=2; ADCIntClear(ADC0_BASE, 3); ADCSequenceDataGet(ADC0_BASE, 3, ADC0Value); } int main(void) { SysCtlClockFreqSet(SYSCTL_XTAL_25MHZ | SYSCTL_OSC_MAIN | SYSCTL_USE_PLL | SYSCTL_CFG_VCO_480, 120000000); InitGPIO(); InitConsole(); InitADC(); InitTimer0(); while(1) { UARTprintf("AIN0 = %d\t", ADC0Value[0]); GPIOPinWrite(GPIO_PORTN_BASE, GPIO_PIN_0 | GPIO_PIN_1, var); UARTprintf("VAR = %d\n",var); SysCtlDelay(10000000); if(var == 4) var = 1; else var*=2; } }