4 years, 10 months ago.

[PROBLEM] LPC1768 Store data on internal storage MbedOS 5

Hi guys,

Objective

I am currently working on a program, in this one I would like to be able to save values in a file. My goal is to be able to do this in a Thread and to be able to add values to the file. I have already done some tests but this leads to errors.

Parameters

I'm on a LPC1768 and i use MbedOS 5.

Test

#include "mbed.h"
 
LocalFileSystem local("local");
DigitalIn button(p12);
DigitalIn button1(p13);
  
DigitalOut led1(LED1);   // add a bit of debug to see if anything is happening 
DigitalOut led2(LED2);

FILE *fp = fopen("/local/out.txt", "a");
 
int hits=0;   // hit counter
 
void write(){
    led2=1;  // use the append to ADD data to the out.txt file
    fprintf(fp,"test %d \r\n", hits);           // add test + hit count to the out.txt file
    fclose(fp);
    led2=0;
}
 
int main(){
    while(button1.read()==1){   // keep looping round wating for button press
    printf("while loop\r\n");
        if(button.read()==0){
            printf("boutton\r\n");
            led1=1;
            write();
            printf("write\r\n");
            while(button.read()==0){
            }               // wait until button released
            led1=0;
            wait_ms(10);    // small delay for debounce
            hits++;         // increase hit counter       
        }
    fclose(fp);
    }    
}

This program is the only one I have managed to make work without any crashes. But the file only appears when I disconnect/replug the mbed and it is empty without any data.

Would anyone have a solution either by using the LocalFileSystem library or any other ?

Thx

Be the first to answer this question.