int main(void) { count=0; SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0); SysCtlADCSpeedSet(SYSCTL_ADCSPEED_250KSPS); ADCSequenceDisable(ADC0_BASE, 1); ADCSequenceConfigure(ADC0_BASE, 1, ADC_TRIGGER_PROCESSOR, 0); ADCSequenceStepConfigure(ADC0_BASE, 1, 0, ADC_CTL_TS); ADCSequenceStepConfigure(ADC0_BASE, 1, 1, ADC_CTL_TS); ADCSequenceStepConfigure(ADC0_BASE, 1, 2, ADC_CTL_TS); ADCSequenceStepConfigure(ADC0_BASE, 1, 3, ADC_CTL_TS | ADC_CTL_IE | ADC_CTL_END); ADCSequenceEnable(ADC0_BASE, 1); // Enable lazy stacking for interrupt handlers. This allows floating-point // instructions to be used within interrupt handlers, but at the expense of // extra stack usage. // ROM_FPULazyStackingEnable(); // Set the system clock to run at 50MHz from the PLL. // ROM_SysCtlClockSet(SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ); // Enable the peripherals used by this example. // ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_SSI2); ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA); SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF); GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3); SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB); GPIOPinTypeGPIOInput(GPIO_PORTB_BASE, GPIO_PIN_2|GPIO_PIN_3); GPIOPinTypeGPIOOutput(GPIO_PORTB_BASE, GPIO_PIN_1); SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0); TimerConfigure(TIMER0_BASE, TIMER_CFG_PERIODIC); // // Configure SysTick for a 100Hz interrupt. The FatFs driver wants a 10 ms tick. // /*ROM_SysTickPeriodSet(ROM_SysCtlClockGet() / 100); ROM_SysTickEnable(); ROM_SysTickIntEnable();*/ /*for the user requirment * here it's generats interupt at every X second. ulPeriod = SysCtlClockGet()*X; TimerLoadSet(TIMER0_BASE, TIMER_A, ulPeriod); */ fr = f_mount(0, &FatFs); if(fr != FR_OK) { GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3,GPIO_PIN_3); // // Delay for a bit // SysCtlDelay(50000); return(1); } //fr = f_mkdir("sub1"); //if (fr) die(fr); if (f_open(&Fil, "DEMO1.csv", FA_WRITE | FA_OPEN_ALWAYS ) == FR_OK) // Create a file { size = (&Fil)->fsize; fr= f_lseek(&Fil,size); fr= f_write(&Fil,"Time,internel_celsius,intenel_fahrenheit\n",39,&bw); fr= f_write(&Fil,"\n",1,&bw); //fr= f_write(&Fil,"Time\r\n",6,&bw); // f_printf(&Fil, "%u", count); /* "1234" */ } fr=f_close(&Fil); //count1="0"; indata16 = 0x0000; GPIOPinWrite(GPIO_PORTB_BASE,CLK, 2); SysCtlDelay(1000000); TimerLoadSet(TIMER0_BASE, TIMER_A,SysCtlClockGet()); IntEnable(INT_TIMER0A); TimerIntEnable(TIMER0_BASE, TIMER_TIMA_TIMEOUT); IntMasterEnable(); TimerEnable(TIMER0_BASE, TIMER_A); // // Enable Interrupts // ROM_IntMasterEnable(); while(1) { if(count>=5) { //IntDisable(INT_TIMER0A); TimerIntDisable(TIMER0_BASE, TIMER_TIMA_TIMEOUT); //IntMasterDisable(); //TimerDisable(TIMER0_BASE, TIMER_A); goto my_data; } ADCIntClear(ADC0_BASE, 1); ADCProcessorTrigger(ADC0_BASE, 1); while(!ADCIntStatus(ADC0_BASE, 1, false)) { } ADCSequenceDataGet(ADC0_BASE, 1, ulADC0Value); } my_data: for(datacount=1;datacount<=5;datacount++) { mydatac1=datacount; itoa(mydatac1,result,10); //this function convert integer to string itoa(bufferulTempValueC[mydatac1],ulTempValueC1,10); //this function convert integer to string itoa(bufferulTempValueF[mydatac1],ulTempValueF1,10); //this function convert integer to string if (f_open(&Fil, "DEMO1.csv", FA_WRITE | FA_OPEN_ALWAYS ) == FR_OK) // Create a file { size = (&Fil)->fsize; fr= f_lseek(&Fil,size); fr = f_write(&Fil,result,2, &bw); fr= f_write(&Fil,",",1,&bw); fr = f_write(&Fil,ulTempValueC1,2, &bw); fr= f_write(&Fil,",",1,&bw); fr = f_write(&Fil,ulTempValueF1,2, &bw); //fr= f_write(&Fil,",",1,&bw); //fr = f_write(&Fil,Hum1,2, &bw); //fr= f_write(&Fil,",",1,&bw); //fr = f_write(&Fil,Temp1,2, &bw); fr= f_write(&Fil,"\n",1,&bw); //f_printf(&Fil, "%u", 1234); /* "1234" */ //fr= f_write(&Fil,"Time\r\n",6,&bw); } fr=f_close(&Fil); //mysdcard(datacount); } } void Timer0IntHandler(void) { counter=counter+1; // Clear the timer interrupt count=count+1; TimerIntClear (TIMER0_BASE, TIMER_TIMA_TIMEOUT); if(GPIOPinRead(GPIO_PORTF_BASE, GPIO_PIN_2)) { GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3, 0); } else { GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_2, 4); } ulTempAvg = (ulADC0Value[0] + ulADC0Value[1] + ulADC0Value[2] + ulADC0Value[3] + 2)/4; ulTempValueC = (1475 - ((2475 * ulTempAvg)) / 4096)/10; ulTempValueF = ((ulTempValueC * 9) + 160) / 5; bufferulTempValueC[count]=ulTempValueC; bufferulTempValueF[count]=ulTempValueF; /*indata=temp_hum(); Hum= indata >>8; //Separate Humidity reading into variable bufferHum[count]=Hum; Temp= indata & 0x00FF; //Separate Temperature reading into variable bufferTemp[count]=Temp;*/ }