#include #include "inc/hw_ints.h" #include "inc/hw_memmap.h" #include "inc/hw_types.h" #include "driverlib/fpu.h" #include "driverlib/gpio.h" #include "driverlib/interrupt.h" #include "driverlib/rom.h" #include "driverlib/sysctl.h" #include "driverlib/systick.h" #include "grlib/grlib.h" #include "utils/cmdline.h" #include "utils/uartstdio.h" #include "fatfs/src/ff.h" #include "fatfs/src/diskio.h" #include "drivers/cfal96x64x16.h" #include "driverlib/timer.h" #include "driverlib/debug.h" #include "driverlib/adc.h" #define PATH_BUF_SIZE 80 #define CMD_BUF_SIZE 64 static FATFS FatFs; static FIL Fil; FRESULT fr; DWORD size; unsigned int bw,count,br,i; unsigned char Second,Hour,Min,Date,Month,Year; //received data from the rtc module char second[],hour[],min[],date[],month[],year[]; //variable which are use forr the converting to string int len,count2; int count1=0; char result[]; unsigned int counter=0; unsigned int indata16, k,indata; //16 bit variables unsigned int Hum, Temp; //8 bit variables unsigned char Hum1[],Temp1[]; //8 bit variables unsigned int bufferHum[], bufferTemp[]; unsigned int mydatac1; unsigned int datacount; #define CLK GPIO_PIN_1 #define RDY GPIO_PIN_2 #define DAT GPIO_PIN_3 unsigned long ulADC0Value[4]; unsigned long ulADC0Value1[4]; volatile unsigned long ulTempAvg; int ulTempValueC; int ulTempValueF; int bufferulTempValueC[]; int bufferulTempValueF[]; volatile unsigned long ulTempAvg1; char ulTempValueC1[]; char ulTempValueF1[]; void SysTickHandler(void) { // // Call the FatFs tick timer. // disk_timerproc(); } // // The error routine that is called if the driver library encounters an error. //***************************************************************************** #ifdef DEBUG void __error__(char *pcFilename, unsigned long ulLine) { } #endif // The program main function. It performs initialization, then runs a command // processing loop to read commands from the console. char *strrev(char *str){ char c, *front, *back; for(front=str,back=str+strlen(str)-1;front < back;front++,back--){ c=*front;*front=*back;*back=c; } return str; } char *itoa(int v, char *buff, int radix_base){ static char table[] = "0123456789abcdefghijklmnopqrstuvwxyz"; char *p=buff; unsigned int n = (v < 0 && radix_base == 10)? -v : (unsigned int) v; while(n>=radix_base){ *p++=table[n%radix_base]; n/=radix_base; } *p++=table[n]; if(v < 0 && radix_base == 10) *p++='-'; *p='\0'; return strrev(buff); } unsigned int temp_hum(void) { signed int j=15; //GPIOPinWrite(GPIO_PORTB_BASE,CLK, 2); // SysCtlDelay(1000000); //delay_ms(100); //delay for 100ms at power up indata16 = 0x0000; SysCtlDelay(500); if(GPIOPinRead(GPIO_PORTB_BASE, RDY)==0) //SysCtlDelay(1000000); { for(j=15;j>0;j-=2) { k = 0; SysCtlDelay(500); if(GPIOPinRead(GPIO_PORTB_BASE, DAT)==8) { //SysCtlDelay(1000000); k = 1 << j; } indata16|=k; GPIOPinWrite(GPIO_PORTB_BASE,CLK, 0); SysCtlDelay(500); while(GPIOPinRead(GPIO_PORTB_BASE, RDY)==0); //SysCtlDelay(1000000); k = 0; SysCtlDelay(500); if(GPIOPinRead(GPIO_PORTB_BASE, DAT)==8) { //SysCtlDelay(1000000); k = 1 << (j-1); } indata16|=k; GPIOPinWrite(GPIO_PORTB_BASE,CLK, 2); SysCtlDelay(500); while(GPIOPinRead(GPIO_PORTB_BASE, RDY)==1); //SysCtlDelay(1000000); } } return indata16; } static void mysdcard(unsigned int mydatac) { //itoa(bufferHum[mydatac],Hum1,10); //this function convert integer to string //itoa(bufferTemp[mydatac],Temp1,10); //this function convert integer to string mydatac1=mydatac; 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 fr=f_open(&Fil, "DEMO1.csv", FA_WRITE | FA_OPEN_ALWAYS ); if (fr == 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); } 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_TIMER1); TimerConfigure(TIMER1_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,ext_Hum,ext_Temp\r\n",56,&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(TIMER1_BASE, TIMER_A,SysCtlClockGet()); IntEnable(INT_TIMER1A); TimerIntEnable(TIMER1_BASE, TIMER_TIMA_TIMEOUT); IntMasterEnable(); TimerEnable(TIMER1_BASE, TIMER_A); // // Enable Interrupts // //ROM_IntMasterEnable(); while(1) { ADCIntClear(ADC0_BASE, 1); ADCProcessorTrigger(ADC0_BASE, 1); while(!ADCIntStatus(ADC0_BASE, 1, false)) { } ADCSequenceDataGet(ADC0_BASE, 1, ulADC0Value); if(count>=5) { IntDisable(INT_TIMER1A); TimerIntDisable(TIMER1_BASE, TIMER_TIMA_TIMEOUT); //IntMasterDisable(); TimerDisable(TIMER1_BASE, TIMER_A); goto my_data; } } my_data: 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); } for(datacount=1;datacount<=5;datacount++) { mysdcard(datacount); } } void Timer1IntHandler(void) { counter=counter+1; // Clear the timer interrupt count=count+1; TimerIntClear (TIMER1_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;*/ }