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;
}
}
}
}