Writing to local file

26 May 2013

Hi . I am trying to store values from from an ADC pin to a local file for every few milliseconds on LPC 11U24 . I first tried running the instructions of opening a file , writing the value and closing inside a loop , it ran for some time and the controller hung. So I ran this test program

<<test program>>

  1. include "mbed.h"

Serial pc(USBTX, USBRX);

LocalFileSystem local("local");

AnalogIn Ain1(p20);

int count=0;

int main() {

while (1) {

pc.printf("\rcount - %d \r\n",count);

FILE* File1 = fopen("/local/datfile.txt","a");

fputc(count, File1);

fclose(File1);

count++; } }

The program stopped after 141 loop. When i kept the opening and closing statements outside the loop and only the writing part inside it kept going for a long time . Could somebody please explain why this is happening . Thank you

25 May 2013

I don't know why it would actually stop working, but in general the localfilesystem is not meant for fast access. It is more used for for example storing configuration data, or writing data to it in chunks.

26 May 2013

So If i want to store values continuously and periodically send these values to a remote location, where do i store them ?

26 May 2013

If not too many values, just store them in an array. You can also store them in an array, and when it is full store the array in localfilesystem. Although that will block for a bit probably while writing the data.