Hi Everyone,
I have been having an issue with the following code when saving Data to EEPROM, I may not understand proeprly how implicit type casting works or maybe is some other thing, so I would like to know exactly why the following behaviour.
/*When doing the following it works perfectly and the output is as expected 0x3664*/
uint16_t word = 0x3664;
uint8_t low_byte = word >> 8;
uint8_t high_byte = word;
EEPROM.write(0x10,low_byte);
EEPROM.write(0x11,high_byte);
Serial.print(F("16 bits Word -> "));
Serial.println(word,HEX);
p = EEPROM.read(0x10)<<8;
p += EEPROM.read(0x11);
Serial.print(F("Read Word -> "));
Serial.println(p,HEX);
/*However when doing the impicit typecasting as parameter of read (), it does not work and I just get
the low byte*/
uint16_t word = 0x3664;
EEPROM.write(0x10,(uint8_t)word>>8);
EEPROM.write(0x11,(uint8_t)word);
Serial.print(F("16 bits Word -> "));
Serial.println(word,HEX);
p = EEPROM.read(0x10)<<8;
p += EEPROM.read(0x11);
Serial.print(F("Read Word -> "));
Serial.println(p,HEX);
I hope I have made myself clear enoguh, thank you very much for your help.
Cheers !