Well, giving a fresh start from here as said...
The defines are:
// System specific constants
#define baud 9600
#define rxBufSize 30
#define txBufSize 70
#define deviceSLlength 10 //10 digit including NULL char [0-9 total 10 + 1]
#define userPasswordLength 5 //4 char incl NULL (dont know why 4 is not working) (eeprom write int is taking 2 extra may be)
Here, deviceSLLength is made 10 because I have a device Serial Number auto generated which is a 10 DIGIT number (stored and used as char. hence 0-9 is my 10 digits and 10th one is \0.
Now, variables are:
//necessary variables for running config (via structure)
char devSL[deviceSLlength]; //10 digit device SL No including NULL char [0-9 total 10 + 1]
boolean optHWEn = false;
boolean debugEn = false;
int targetTemp = 4; //default
unsigned int deltaT = 4; //default Delta T = 4
unsigned int opsMode = 1; //default ops mode = 1
unsigned long compressorRunTime; //default 12
unsigned long defrostTime; //default 30
char userPass[userPasswordLength] = "1111"; //default user password is 1111
Hope this above part is self explanatory. The data types are made like this intentionally and not that willing to change them. The initial values are the default values, but when eeprom read will be done, then these will be changed for damn sure. Why, I will explain later. About initial values here given, they will give a hint what may be the value. Still for more hint, all unsigned values will NEVER be negative. Int (signed int) may be positive or negative, but value will be within -50 to +50 kind of thing. I checked, it needs 2 bytes with min/max of my possibilities.
The unsigned LONG variables here are actually storing simple integer, means they don't need that looong here, rather that same 2 byte. one will be max 24, and other will be max 30. The reason i declared this variable LONG because after reading from eeprom a 2 digit integer, which represents hours (hence default 12hrs) in storage (user inputs hours) and it is used by millis() function where it is multiplied by 3600000. Thus after reading from eeprom this same value 12 turns into more...
and the password: It's just though i am saying 4 digit PIN code, but it can be anything within 4 chars. So better let's stick with 4 digit, defauly hence 1111. So practically the variable needs 0-3 + 1 = 4 in size. (but if I dont use 5 as size, i face another issue, which started this thread. Will discuss later.)
My eeprom address map is below:
//EEPROPM Addressings need to be re-check for more optimization
#define eepromOffset 0 //[Address 0, reserved]
#define deviceSLAddr (eepromOffset + 1) //[Start at 1, used for device SL (10byte incl NULL), ends at 11]
#define optHWEn_eepromAddr (deviceSLAddr + 11) //[Start at 1+11=12, used for 1byte, ends at 12]
#define debugEn_eepromAddr (optHWEn_eepromAddr + 1) //[Start at 12+1=13, used for 1byte, ends at 13]
#define targetTemp_eepromAddr (debugEn_eepromAddr + 1) //[Start at 13+1=14, used for 2byte, ends at 15]
#define deltaT_eepromAddr (targetTemp_eepromAddr + 2) //[Start at 15+2=17, used for 1byte, ends at 17]
#define opsMode_eepromAddr (deltaT_eepromAddr + 1) //[Start at 16+1=17, used for 1byte, ends at 17]
#define compressorRunTime_eepromAddr (opsMode_eepromAddr + 1) //[Start at 17+1=18, used for 1byte, ends at 18] //we may avoid it and can put this in a variable as per update.
#define defrostTime_eepromAddr (compressorRunTime_eepromAddr + 1) //[Start at 18+1=19, used for 1byte, ends at 19]
#define userPassword_eepromAddr (defrostTime_eepromAddr + 1) //[Start at 19+1=20, used for 4byte, ends at 23]
Please consider, the manual calculation in comments are not accurate. The sizeof(varname) did not helped me that much I dont know why, but will make a further trial again surely.