//* DriverLib Includes */ #include "driverlib.h" /* Standard Includes */ #include #include /* variable intialization */ static volatile uint16_t curADCResult,dval,i,j; static volatile uint32_t dec; static volatile float resultsBuffer[UINT8_MAX],d; static volatile uint8_t resPos; char itos[8]={0,}; /* UART configuration with 9600 baud rate and 48MHZ clock*/ const eUSCI_UART_Config uartConfig = { EUSCI_A_UART_CLOCKSOURCE_SMCLK, // SMCLK Clock Source 312, // BRDIV = 78 8, // UCxBRF = 2 0, // UCxBRS = 0 EUSCI_A_UART_NO_PARITY, // No Parity EUSCI_A_UART_LSB_FIRST, // MSB First EUSCI_A_UART_ONE_STOP_BIT, // One stop bit EUSCI_A_UART_MODE, // UART mode EUSCI_A_UART_OVERSAMPLING_BAUDRATE_GENERATION // Oversampling }; int main(void) { /* Halting the Watchdog */ WDT_A_holdTimer(); /* temporary and count variable*/ curADCResult = 0; resPos = 0; /* Setting DCO to 48MHz */ CS_setDCOCenteredFrequency(CS_DCO_FREQUENCY_48); /* Setting MCLK to REFO at 48MHz for LF mode */ CS_initClockSignal(CS_MCLK, CS_DCOCLK_SELECT, CS_CLOCK_DIVIDER_1); PCM_setPowerState(PCM_AM_LF_VCORE0); /* Enabling the FPU for floating point operation */ FPU_enableModule(); FPU_enableLazyStacking(); /* Selecting P1.2 and P1.3 in UART mode */ GPIO_setAsPeripheralModuleFunctionInputPin(GPIO_PORT_P1, GPIO_PIN1 | GPIO_PIN2 | GPIO_PIN3, GPIO_PRIMARY_MODULE_FUNCTION); /*setting P2.5 as output and initializing to 0*/ GPIO_setAsOutputPin(GPIO_PORT_P2, GPIO_PIN5); GPIO_setOutputLowOnPin(GPIO_PORT_P2, GPIO_PIN5); /*setting LED Pin P1.0 as output and initializing to 0*/ GPIO_setAsOutputPin(GPIO_PORT_P1, GPIO_PIN0); GPIO_setOutputLowOnPin(GPIO_PORT_P1, GPIO_PIN0); /* Configuring GPIOs (5.5 A0) */ GPIO_setAsPeripheralModuleFunctionInputPin(GPIO_PORT_P5, GPIO_PIN5, GPIO_TERTIARY_MODULE_FUNCTION); /* Initializing ADC (MCLK/1/4) */ ADC14_enableModule(); ADC14_initModule(ADC_CLOCKSOURCE_MCLK, ADC_PREDIVIDER_1, ADC_DIVIDER_4, 0); /* Configuring ADC Memory */ ADC14_configureSingleSampleMode(ADC_MEM0, true); ADC14_configureConversionMemory(ADC_MEM0, ADC_VREFPOS_AVCC_VREFNEG_VSS, ADC_INPUT_A0, false); /* Configuring Sample Timer */ ADC14_enableSampleTimer(ADC_MANUAL_ITERATION); /* Configuring UART Module */ UART_initModule(EUSCI_A0_MODULE, &uartConfig); /* Enable UART module */ UART_enableModule(EUSCI_A0_MODULE); /* disabling UART receive interrupts */ UART_disableInterrupt(EUSCI_A0_MODULE, EUSCI_A_UART_RECEIVE_INTERRUPT); Interrupt_disableInterrupt(INT_EUSCIA0); /* Configuring Timer32 in periodic mode */ Timer32_initModule(TIMER32_0_MODULE, TIMER32_PRESCALER_1, TIMER32_32BIT, TIMER32_PERIODIC_MODE); /* setting count value to timer register*/ Timer32_setCount(TIMER32_0_MODULE,1090); /* enabling timer interrupts*/ Timer32_enableInterrupt(TIMER32_0_MODULE); /* starting timer32*/ Timer32_startTimer(TIMER32_0_MODULE, true); /* Enabling interrupts */ Interrupt_enableInterrupt(INT_T32_INT1); Interrupt_enableMaster(); /* Sleeping when not in use */ while (1) { PCM_gotoLPM0(); } } /* Timer32 ISR */ void timer32_isr(void) { /* clearing Timer32 interrupt flag*/ Timer32_clearInterruptFlag(TIMER32_0_MODULE); /* toggling P1.0 and P2.5*/ GPIO_toggleOutputOnPin(GPIO_PORT_P2, GPIO_PIN5); GPIO_toggleOutputOnPin(GPIO_PORT_P1, GPIO_PIN0); /*enabling ADC Conversion*/ ADC14_enableConversion(); /* transferring ADC result to a variable*/ curADCResult = ADC14_getResult(ADC_MEM0); /*ADC value conversion with respect to reference Voltage and storing it in array*/ resultsBuffer[resPos] = (curADCResult * 3.3) / 16384; resPos++; /* float value to string conversion*/ d = (curADCResult * 3.3) / 16384; dval=d; dec= (int)(d*100000)%100000; itos[7]='\n'; for(i=6;i>=2;i--) { itos[i]=(dec%10)+'0'; dec=dec/10; } itos[1]='.'; itos[0]=(dval%10)+'0'; /* Enabling/Toggling Conversion */ ADC14_toggleConversionTrigger(); /*transmitting converted values*/ for(j=0;j<8;j++) { UART_transmitData(EUSCI_A0_MODULE,itos[j]); } /* resetting timer32 register with count and starting it again*/ Timer32_setCount(TIMER32_0_MODULE,1090); Timer32_startTimer(TIMER32_0_MODULE, true); }