Hello everybody?
I am making a data logger where i store ma values from my accelerosensor( X,Y and Z) to a sd card.
I already solved some issues, but now i have a issue with ghost value. When i read de data that are stored in the SD card, they dont match with the real data and random number are added to it.
I should have values between 0 and 2000. but sometimes I even got values of 110000. Could someone help me with this please?
Also It does not print in a new line after the 3 values are printen. I tought "\r\n" was the correct syntax?
#define TARGET_IS_TM4C129_RA1 #include <stdint.h> #include <stdbool.h> #include <string.h> #include <stdio.h> #include "inc/hw_memmap.h" #include "inc/hw_types.h" #include "driverlib/gpio.h" #include "driverlib/rom.h" #include "driverlib/rom_map.h" #include "driverlib/ssi.h" #include "driverlib/sysctl.h" #include "driverlib/systick.h" #include "driverlib/pin_map.h" #include "driverlib/adc.h" #include "diskio.h" #include "ff.h" #include "ffconf.h" #include "driverlib/fpu.h" #include "stdlib.h" volatile uint32_t g_ui32SysClock; static FATFS g_sFatFs; // The following are data structures used by FatFs. static FIL fil; FRESULT iFResult; uint32_t value[3]; volatile uint32_t valueX; volatile uint32_t valueY; volatile uint32_t valueZ; char strValue[10]; uint32_t count = 8*1024; uint32_t counter=0; int main(void) { FPULazyStackingEnable(); // enables floating point g_ui32SysClock= SysCtlClockFreqSet((SYSCTL_XTAL_25MHZ | SYSCTL_OSC_MAIN | SYSCTL_USE_PLL | SYSCTL_CFG_VCO_480), 8000); SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0); SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE); // enable adc and gpio ADCHardwareOversampleConfigure(ADC0_BASE, 64); GPIOPinTypeADC(GPIO_PORTE_BASE, GPIO_PIN_1 |GPIO_PIN_2 | GPIO_PIN_3); FPUEnable(); SysTickPeriodSet(g_ui32SysClock / 100); SysTickEnable(); SysTickIntEnable(); ADCSequenceDisable(ADC0_BASE,1); ADCSequenceConfigure(ADC0_BASE, 1, ADC_TRIGGER_PROCESSOR, 0); ADCSequenceStepConfigure(ADC0_BASE,1, 0, ADC_CTL_CH0); ADCSequenceStepConfigure(ADC0_BASE,1, 1, ADC_CTL_CH1); ADCSequenceStepConfigure(ADC0_BASE,1, 2, ADC_CTL_CH2|ADC_CTL_IE| ADC_CTL_END); ADCSequenceEnable(ADC0_BASE, 1); iFResult = f_mount(0, &g_sFatFs); while(1) { iFResult = f_open(&fil, "testfile.txt",FA_OPEN_ALWAYS|FA_WRITE); iFResult = f_lseek(&fil, f_size(&fil)); // moves the file read/write pointer of an open file object. ADCIntClear(ADC0_BASE, 1); ADCProcessorTrigger(ADC0_BASE, 1); while(!ADCIntStatus(ADC0_BASE, 1, false)) { } ADCSequenceDataGet(ADC0_BASE, 1,value); valueX = value[0]; valueY = value[1]; valueZ = value[2]; iFResult = f_mount(0, &g_sFatFs); iFResult = f_open(&fil, "testfile.txt",FA_OPEN_ALWAYS|FA_WRITE); iFResult = f_lseek(&fil, f_size(&fil)); // moves the file read/write pointer of an open file object. sprintf(strValue,"%d, %d,%d\r\n",valueX,valueY,valueZ); iFResult = f_write(&fil, &strValue,4, &count); iFResult = f_close(&fil); } // f_mount(0, NULL); }