Writing binary file on sd card with LPC2148

Hi, I’m using a LPC2148 with three sensors and my goal is to save sensor data every 10ms. For now , the data are saved in CSV file, so in text mode but I’m trying to save them in a file in binary mode without success.

I’m using some libraries like fat16, sd_raw, rootdir… and I don’t know where I can indicate that I want to write the data in a binary mode !

Any ideas ???

Writting to an SD file in binary is no different than in ASCII. When you write the string “ABC123” to the file, you are writting the numbers 65,66,67,49,50,51 to the file.

Only by the ASCII convention do we associate those numbers with those characters.

I assume you have some methods to write data to a SD file. For ASCII you are likely using something like sd.printf(“ABC123”). For binary you will likely find a “write” method.

If you want to write to the file you might have something LIKE:

char buf[128];

// Add data to buf

for (i=0; i<128; i++) buf = i;
sd.write(buf, 128); // Write 128 bytes from buf to SD file
To read binary data you likely will have a read function that works in a similar way.
The exact syntax will depend on what library you are using.

Thank you, I thought it was more complicate than that ! I was writing the data via sprintf and an other write method so I guess it is for that the data was in text mode !

Again, thanks for the reply :slight_smile: