I'm trying to save in memory (FRAM in this case) DOUBLE value, i try the same method with use of UNION for save FLOAT value, but don't go over the 2nd number after dot, why? Where I'm wrong? thank's for help .
//---------------------------------------------------------
union Scomp_double // si utilizza union x double
{
double temp;
char byte_s[8];
} S_double;
//---------------------------------------------------------
double mioDouble = 1234567.12345678;
//-------------------------DOUBLE--------------------------------
Serial.println("DOUBLE");
byte d0 = 0; // contengono i byte del float
byte d1 = 0;
byte d2 = 0;
byte d3 = 0;
byte d4 = 0;
byte d5 = 0;
byte d6 = 0;
byte d7 = 0;
S_double.temp = mioDouble;
d0 = S_double.byte_s[0];
d1 = S_double.byte_s[1];
d2 = S_double.byte_s[2];
d3 = S_double.byte_s[3];
d4 = S_double.byte_s[4];
d5 = S_double.byte_s[5];
d6 = S_double.byte_s[6];
d7 = S_double.byte_s[7];
Serial.println(d0);
Serial.println(d1);
Serial.println(d2);
Serial.println(d3);
Serial.println(d4);
Serial.println(d5);
Serial.println(d6);
Serial.println(d7);
fram.writeEnable(true);
fram.write8(11, d0);
fram.writeEnable(false);
fram.writeEnable(true);
fram.write8(12, d1);
fram.writeEnable(false);
fram.writeEnable(true);
fram.write8(13, d2);
fram.writeEnable(false);
fram.writeEnable(true);
fram.write8(14, d3);
fram.writeEnable(false);
fram.writeEnable(true);
fram.write8(15, d4);
fram.writeEnable(false);
fram.writeEnable(true);
fram.write8(16, d5);
fram.writeEnable(false);
fram.writeEnable(true);
fram.write8(17, d6);
fram.writeEnable(false);
fram.writeEnable(true);
fram.write8(18, d7);
fram.writeEnable(false);
S_double.byte_s[0] = fram.read8(11); // si ricompone il double
S_double.byte_s[1] = fram.read8(12);
S_double.byte_s[2] = fram.read8(13);
S_double.byte_s[3] = fram.read8(14);
S_double.byte_s[4] = fram.read8(15);
S_double.byte_s[5] = fram.read8(16);
S_double.byte_s[6] = fram.read8(17);
S_double.byte_s[7] = fram.read8(18);
double masterDouble = S_double.temp;
Serial.println(masterDouble);
//-------------------------DOUBLE-------------------------------
expected result 1234567.12345678 , result taken 1234567,12
double
on Arduino is 4 bytes. The same as afloat
.