8 years, 2 months ago.

buffers

<<code>>

  1. include "mbed.h"
  2. include "ADXL345.h"
  3. include "SDFileSystem.h"

SDFileSystem sd(D11, D12, D13, D4, "sd"); MOSI, MISO, SCLK, SSEL ADXL345 accelerometer(PC_3,PC_2,PB_10,PA_8);

Serial pc(USBTX, USBRX);

char fileName[20]; Ticker fileUpdate; FILE *logFile = NULL;

void onFileUpdate(void) { static int fileNumber = 0; if (logFile) fclose(logFile); char fileName[20]; sprintf(fileName,"/sd/PCEdata%02d.txt",fileNumber++); logFile = fopen(fileName,"w");

pc.putc('\n'); }

const int S25FLSize = 2000000; size of a page in bytes

const int s25flBlockSize = 256;sizeof(dataStore); size needed to store a data structure

int main(void) { pc.baud(921600);

set_time(1387188323); Set RTC time to 16 December 2013 10:05:23 UTC int readings[3] = {0, 0, 0}; pc.printf("Starting ADXL345 test...\n"); wait(.001); pc.printf("Device ID is: 0x%02x\n", accelerometer.getDevId()); wait(.001);

accelerometer.setPowerControl(0x00); wait(.001); accelerometer.setDataFormatControl(0x0B); wait(.001); accelerometer.setDataRate(0x0F); wait(.001); accelerometer.setPowerControl(0x08);

onFileUpdate(); open the first log file; fileUpdate.attach(onFileUpdate,10); every minute switch to a new log file.

int recordNumber = 0;

int buf_position; char acc_storebuffer[256]; bool buf_full ; while(1) {

memset(&acc_storebuffer,0,sizeof(acc_storebuffer)); buf_position = 0; buf_full = true; while(buf_full){ if(buf_position >= sizeof(acc_storebuffer) ) buf_full = false;

accelerometer.getOutput(&acc_storebuffer[buf_position]); buf_position +=6; }

fprintf(logFile,"\r\n X: %ig, Y: %ig, Z: %ig", (acc_storebuffer[ buf_position+0] | (acc_storebuffer[buf_position + 1] <<8)), (acc_storebuffer[buf_position + 2] | (acc_storebuffer[buf_position + 3] <<8)),(acc_storebuffer[buf_position + 4] | (acc_storebuffer[buf_position + 5] <<8)));

} } }

<</code>>

Be the first to answer this question.