I'm working on a project where I need to save sensor data to flash. I'll probably use the 64 mbit SST26VF064B by Microchip. I've used it in projects for over two years now and have always liked it. In the past, when logging data, I would simply write the data one line at a time in comma delimited ASCII format, complete with separate bytes for each comma, carriage, return, etc. For instance, let's say I needed to save temperature, pressure, and voltage one entry/line at a time:
Temp = 13 deg C
Pressure = 5.2 psi
Voltage = 3.2 V
I would write the following data to the Flash one ASCII character at a time:
That's a total of 10 bytes (not including Carriage Return and/or checksum). It's not very efficient, but it's simple since I can read the Flash directly into a .CSV file. Unfortunately in my latest application I am needing to save large amounts of data per entry for long periods of time. I need a vastly more efficient way of saving data.
What if, instead, I saved the data as follows: (Note: to keep this example simple, just assume I can keep track of my decimal places and none of my data has negative values.)
Now instead of 10 bytes, it's only 3 bytes. The issue here is there's no way to mark the end of a data entry/line with Carriage Return. If I'm reading the Flash and I get off by one byte in the three byte data sequence, none of the data will be correct. I can't use the carriage return byte since this is $0D. Every time there is a 13 in my data, things will get thrown off. Is there a simple trick to use in this type of scenario that I'm just not aware of? If anyone knows the solution to this problem, please share or link to it. One idea I had was to use a unique combination of bytes to mark the end of a line of data. This seems cumbersome, and in theory, the data could in rare instances match my unique combination of bytes. Another idea was to check each byte as I write it to the buffer. If it's a 13, change it to a 14. Is it really that big a deal to log 14 deg C when it's 13 deg C outside? I could even add an extra byte to my data entry that logs any of these ghost "13's" so that the applicable 14's gets changed back to a 13 when the data is read back. Let's just hope this extra byte is never a 13.
For those who are interested, here's a good read on integrating the Propeller with Flash