Hello All,
This code reads in a string of floating point numbers to the Teensy and places it it an array. What I am having trouble with is then storing the values in EEPROM, so they don;t have to be updated every time new firmware is pushed to the Teensy.
Internally, it appears a float is 32 bits on a Teensy 4.0, and I assume it's represented in IEEE754 format on the actual internal data bus. I'm trying a shortcut to this method,
https://github.com/MalcolmMcLean/ieee754/blob/master/binaryio.c which actually looks at the parts of the float. I'm probably mistaken, but it seems to me that one should be able to break the 32 bit float into bytes and write them to 4 locations in EEPROM, then, use the reverse process to re-create the original float.
But, I get this error
when I try to make a byte conversion in here:
The complete sketch is attached, feel free to use this if helpful.
Regards All,
-jb
This code reads in a string of floating point numbers to the Teensy and places it it an array. What I am having trouble with is then storing the values in EEPROM, so they don;t have to be updated every time new firmware is pushed to the Teensy.
Internally, it appears a float is 32 bits on a Teensy 4.0, and I assume it's represented in IEEE754 format on the actual internal data bus. I'm trying a shortcut to this method,
https://github.com/MalcolmMcLean/ieee754/blob/master/binaryio.c which actually looks at the parts of the float. I'm probably mistaken, but it seems to me that one should be able to break the 32 bit float into bytes and write them to 4 locations in EEPROM, then, use the reverse process to re-create the original float.
But, I get this error
Code:
invalid operands of types 'float' and 'int' to binary 'operator>>'
Code:
float fwriteToEEPROM(float floatToWrite, int fp){
int n;
unsigned char toEEPROM;
for ( n=0; n<4; n++){
toEEPROM = (char)(floatToWrite >> n*8) & 0xFF;
EEPROM.write(toEEPROM, fp+n); delay(4);
}
return freadFromEEPROM(int fp); // Return what was written to confirm.
}
Regards All,
-jb