Could someone point me to some example code of how I can write some information (e.g. temperature readings) to the flash memory?
Depends on how you want to do it. But either way see examples in the SPIFlash library (https://github.com/LowPowerLab/SPIFlash).
Pedro Albuquerque has a very nice library to use on Moteinos Flash memory in his GITHub, called FlashLogM.
Here are the available functionalities of the library:
QuoteWelcome to the FlashLogM wiki!
FlashLogM
This library implements a class to make data Log handling easy, providing a set of functionalities that abstract code from the details on reading and writing to a Flash memory, on Moteino boards.
The standard flash memory (on Moteino) is typically a 4Mbit memory (256KB) .
The data to store in the Log can be of any type, and all development was based on a struct data type.
Base concepts
A Log will be a sequence of data stored in the flash memory;
A pointer is always set to the next available write address and updated on every write;
A pointer is always set to the next read address and updated on every read so that you can do a sequential read of the Log, starting on the first data stored and independently of the write position;
Once memory is full, it will wrap around and will start writing again from position 0. Once this happens, a switch is set (memWrap) with no influence on Log usage. The wrap around feature does not change the way you use the saveData and readData methods;
So that this wrap around mechanism can work, new Data must start with a signature header of "/*";
Example:
struct mytype {
char HD[3] = "/*"; //New data signature header
uint8_t hour;
uint8_t minute;
uint8_t seconds;
uint16_t miliseconds;
uint8_t day;
uint8_t month;
uint8_t year;
float groundspeed;
}
Base functions
saveData(&yourDataVar) - Write data to the next Log position;
readData(&yourDataVar) - Read data from the next Log position;
eraseData() - Clear the flash memory;
eraseNext4K(address) - Erase a 4KByte block starting on address;
initialize - This method will search for the first store data in the Log to set the next read pointer and the last one to set the next write pointer. It will also determine the number of stored Log records;
Other functions: nextWrite, nextRead, numRecords, recSize, maxRecords;
The library is here:
https://github.com/Pedroalbuquerque/FlashLogM (https://github.com/Pedroalbuquerque/FlashLogM)
He's a member of lowpowerlab forum, so if you need help on this just contact him
Did anyone had a go on trying this library? It is really easy to use the flash chip to log data with this lib.
I am trying to get it to work but the IDE appears to have an issue with it. It is giving me an error stating that "Category 'Flash memory' in library FlashLogM is not valid. Setting to 'Uncategorized'" I don't really know if it's an issue with the library or my code, but I suspect it's the library. It looks properly installed.
Can you please post the code you are trying to use and also what version of the IDE?
Hi Luisr320 and Rhood,
a few more information would help to diagnose the problem source, as used board, IDE version, code used.
Just in case i see a gap here that I am trying to address by sharing the code I have used to test the library.
Github has now a "example" folder were you can find the "testFlash" project .
The functionality on the example are very basic to allow to test the read and write, or even clean of the Flash using the lib methods.
Maybe you can try to use it and share the results or any additional doubts you may face while trying.
Just let me know.
Cheers, Pedro