How to use Dash Flash Memory Read and Write

Well, this is embarrassing… Now that we have access via the Dash class to FLASH memory, I have to confess that I’m pretty inexperienced in this area.

My need/goal is simple: Let’s say I have an integer variable named FRED. Every once in a great while, I would like to take the value of FRED and write it to flash memory. I would do that such that I could recall it later and use it in my program. So, I’m basically looking for a way to write FRED to the Flash memory, and then recall it later.

Does anybody have any sample code snippets, or place where they could point me? I’ve looked for examples across the web, and on the Arduino forms, but the Dash class seems to be unique enough that I could spend my wheels forever.

Any hints or help are greatly appreciated. I’m honestly not asking anybody to write my code for me; but just to give me an idea beyond what is in the very sketchy example for the Dash API (which is really not much of an example…)

Thanks very much!

Michael

So we are going to add more of an EEPROM interface at some point to abstract things a bit and make it more similar to what other arduino style boards look like. For now, you can follow our example code in the docs and you would just have a specific address for the variable you’re writing.

So FRED could be stored at address 0 and you could cast it back and forth to whatever type it is.

Hi Michael, I spent quite some time working on this myself! Below are two functions I adapted from the API docs that seem to be working well for me so far. I’d love any feedback if anyone has any!

String writeToFlash(char array2write[], uint32_t writeAddress, uint32_t writeSector, int infoSize) {

  //erase the sector so it can be written
  DashFlash.eraseSector(writeSector);
  //DashFlash.eraseAll();
  //start at address 32 (MUST be a multiple of 8)
  DashFlash.beginWrite(writeAddress);

  //write the array to memory bit by bit (lol)
  for(int i=0; i<(infoSize); i++) {
    DashFlash.continueWrite(array2write[i]);
  }
  //complete the write to flash
  DashFlash.endWrite();

  //Read back and verify write
  char f_read[infoSize];
  DashFlash.beginRead(writeAddress);
  for(int i=0; i<(infoSize); i++)
  {
    f_read[i] = DashFlash.continueRead();
  }
  DashFlash.endRead();

  String f_readString(f_read); //convert back to string to be analysed
  return f_readString;
}

and

String readFromFlash(uint32_t readLocation, int infoSize) {
  char f_read[infoSize];
  DashFlash.beginRead(readLocation);
  for(int i=0; i<infoSize; i++)
  {
    f_read[i] = DashFlash.continueRead();
  }
  DashFlash.endRead();

  String f_readString(f_read); //convert back to string to be analysed
  return f_readString;
}

basically the first takes the array you want to write, the location you want to write it, the sector that that location is in (to be erased first), and the size of the array you’re writing. it then feeds back a string of what was written (for error handling). the second is just a simple read function that can be handed the same variables for later recall.

Thanks, Reuben. Count me as one of the people who would like to see this.

Thank you! This might be exactly what I’m looking for.

I’ll test it out and keep you posted.

Thanks so much for taking the time to post this.

Of course. Let me know how it works out for you!

– deleted –

(yes, still trying to learn on my own, ladies and gentlemen…)

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.