Please explain flash.write to write data in flash approx size 6-7kb Arduino DUE

Hello,

What is max data i can store in flash of Arduino DUE?

I am able to write data to flash using struct.

stepStruct struct have 600-700 bytes

Write/read one is ok.
memcpy(BytAry, &_step1, sizeof(stepStruct));
flash.write(180, BytAry, sizeof(stepStruct));

Write/read sec is Not ok.
memcpy(BytAry, &_step2, sizeof(stepStruct));
flash.write(1000, BytAry, sizeof(stepStruct));

Please Help!!

Did you try DueFlashStorage library ?

Yes,

memcpy(BytAry, &_step2, sizeof(stepStruct));
flash.write(1000, BytAry, sizeof(stepStruct));

Used structure example from that library.

Post the entire code you are actually using.

Thanks, Its resolved.
Able to read and write flash, Struct array has been used too.
Here is the test code by the way

#include <LiquidCrystal.h>
#include <DueFlashStorage.h>
DueFlashStorage flash;

LiquidCrystal lcd(9, 11, 12, 13, SDA1, SCL1);

#define PIN_LCD_BACK_LIGHT 8
#define PIN_LCD_RST7 7
#define PIN_LCD_PS10 10

float a = 299.9;
float b = 40.5;
float c = 15.5;
float d = 100;
int e = 20;

float n[20];
float o[20];
float p[20];
float q[20];
float r[20];
float s[20];
int t[20];
char prog[12]=“Profile”;

struct stepStruct {
float a;
float b;
float c;
float d;
int e;
float n[20];
float o[20];
float p[20];

float q[20];
float r[20];
float s[20];
int t[20];

char prog[12];
char ch;
};
stepStruct _step1;
stepStruct _step2;

stepStruct *ptrStep1;
stepStruct *ptrStep2;

struct stepStruct *_stepPtrAry[10], _stepAry[10];

char inStr[1000];
int serInx = 0 ;
String outStr = “” ;
bool strComp = false ;
int pNum = 0 ;
int k1 = 0;
int k = 0;

void setup() {
lcd.begin(20, 4);
pinMode(PIN_LCD_BACK_LIGHT, OUTPUT); // LCD BACK LIGHT
digitalWrite(PIN_LCD_BACK_LIGHT, HIGH);
pinMode(PIN_LCD_RST7, OUTPUT); // LCD 5V : LOW TO RESET DISPLAY (7in SFC card) (10 in power supply)
digitalWrite(PIN_LCD_RST7, HIGH);
pinMode(PIN_LCD_PS10, OUTPUT); // LCD 5V : LOW TO RESET DISPLAY (7in SFC card) (10 in power supply)
digitalWrite(PIN_LCD_PS10, HIGH);
Serial.begin(9600);
ptrStep1 = &_step1;
ptrStep2 = &_step2;
}

void loop() {

if ( inStr[7]== ‘S’ && inStr[8]== ‘E’ && inStr[9]== ‘T’ && strComp == true )
{
Serial.print(inStr[10]);Serial.print(",");
pNum = chr2int(inStr[10]) -1;
if (pNum >9 || pNum <0)
pNum=0;
Serial.print(pNum);Serial.print(",");
a = getValue(11)/10;
Serial.print(a);Serial.print(",");
b = getValue(16)/10;
Serial.print(b);Serial.print(",");
c = getValue(21)/10;
d = getValue(26); // /10;
e = getValue(31)/10;
k1 = 36; // NEXT BYTE
for (k=0 ; k<20; k++)
{
n[k] = getValue(k1)/10; k1=k1+5;
o[k] = getValue1(k1); k1=k1+6;
p[k] = getValue1(k1); k1=k1+6;
q[k] = getValue(k1)/10; k1=k1+5;
r[k] = getValue1(k1); k1=k1+6;
s[k] = getValue1(k1); k1=k1+6;
t[k] = getValue(k1); k1=k1+5;
}

if (pNum ==0)
{ //prog = “Prof1”;
saveStep1(pNum); }
else
{ //prog = “Prof2”;
saveStep2(pNum); }

outStr = “”;
outStr = outStr + pNum + " Successfully Saved. " ;
Serial.println(outStr);

strComp = false;
for (serInx=0; serInx<1000; serInx++)
inStr[serInx] = ’ ';
serInx = 0;
}
else if ( inStr[7]== ‘L’ && inStr[8]== ‘O’ && inStr[9]== ‘D’ && strComp == true ) //SEND-PROFILE-VALUES TO RS232/LAPTOP
{
pNum = chr2int(inStr[11]) -1;
if (pNum > 9 || pNum <0)
pNum = 0;
Serial.println(pNum);
if (pNum ==0)
readStep1(pNum);
else
readStep2(pNum);

// readStepAry(pNum);
outStr = “”;
outStr = outStr + pNum + " Successfully Loaded. " ;
Serial.println(outStr);
strComp = false;
for (serInx=0; serInx<1000; serInx++)
inStr[serInx] = ’ ';
serInx = 0;
}
else if (strComp == true )
{
strComp = false;
for (serInx=0; serInx<1000; serInx++)
inStr[serInx] = ’ ';
serInx = 0;
}

lcd.clear();
lcd.setCursor(0,0);
lcd.print(pNum); lcd.print(": “);
lcd.print(String(a,1)); lcd.print(”: “);
lcd.print(String(b,1)); lcd.print(”: “);
lcd.print(String(c,1)); lcd.print(”: ");
lcd.setCursor(0,1);
lcd.print(ptrStep1->prog);

lcd.setCursor(0,2);
lcd.print(ptrStep2->prog);

delay(100);
}

String readProgName(int i)
{
String str = “xxxxxxx”;
str = _stepPtrAry*->prog;*

  • return str;*
    }
    void saveStep1(int st)
    *{ *
  • int i = 0; *
  • _step1.a = a;*
  • _step1.b = b;*
  • _step1.c = c;*
  • _step1.d = d;*
    _step1.e = e;
  • for (i=0 ; i<20; i++)*
  • {*
    step1.n _ = n*;*
    step1.o _ = o*; *
    step1.p = p*;*
    step1.q _ = q*;*
    step1.r _ = r*;*
    step1.s _ = s*;*
    step1.t _ = t*;*
    * }_
    //_step.prog =prog;
    memcpy(_step1.prog, &prog, sizeof(prog));
    _step1.ch = ‘X’;*

* byte BytAry[sizeof(stepStruct)]; *
* memcpy(BytAry, &step1, sizeof(stepStruct)); *
* flash.write(0, BytAry, sizeof(stepStruct));
}
void readStep1(int st)
{
byte BytAry = flash.readAddress(0); _

* memcpy(&_step1, BytAry, sizeof(stepStruct));
a = _step1.a;
b = _step1.b;
c = _step1.c;
d = _step1.d;
e = _step1.e;*

* memcpy (prog, step1.prog, sizeof(prog));
memcpy (n, step1.n, sizeof(n));
memcpy (o, step1.o, sizeof(o));
memcpy (p, step1.p, sizeof(p));
memcpy (q, step1.q, sizeof(q));
memcpy (r, step1.r, sizeof(r));
memcpy (s, step1.s, sizeof(s));
memcpy (t, step1.t, sizeof(t));*
}

void saveStep2(int st)

*{ *

* int i = 0; *

* step2.a = a;
step2.b = b;
step2.c = c;
step2.d = d;
step2.e = e;*
* for (i=0 ; i<20; i++)*

* {*

step2.n _ = n*;*
step2.o _ = o*; *
step2.p = p*;*
step2.q _ = q*;*
step2.r _ = r*;*
step2.s _ = s*;*
step2.t _ = t*;*
* }*

* //_step.prog =prog;
memcpy(_step2.prog, &prog, sizeof(prog)); // copy the struct to the byte array*

* _step2.ch = ‘X’;*

* byte BytAry[sizeof(stepStruct)]; *
* memcpy(BytAry, &step2, sizeof(stepStruct)); *
* flash.write(1000, BytAry, sizeof(stepStruct));
}
void readStep2(int st)
{
byte BytAry = flash.readAddress(1000); _

* memcpy(&_step2, BytAry, sizeof(stepStruct));
b = _step2.b;
c = _step2.c;
d = _step2.d;
e = _step2.e;*

* memcpy (prog, step2.prog, sizeof(prog));
memcpy (n, step2.n, sizeof(n));
memcpy (o, step2.o, sizeof(o));
memcpy (p, step2.p, sizeof(p));
memcpy (q, step2.q, sizeof(q));
memcpy (r, step2.r, sizeof(r));
memcpy (s, step2.s, sizeof(s));
memcpy (t, step2.t, sizeof(t));*
}

/* EVENTS */

void serialEvent() {

while (Serial.available()) {

* // get the new byte:*
* char inChar = (char)Serial.read();*

* inStr[serInx] = inChar;*
* serInx++;*
* if (inChar == ‘X’ || inChar == ‘x’) {*
* {*
* Serial.print(inChar); strComp = true;*
* }*

* }*
}
}