Eeprom usage
-
You'll find the addresses used here:
https://github.com/mysensors/Arduino/blob/master/libraries/MySensors/MySensor.h#L44If you only need 256 bytes you can use the library functions saveState()/loadState() which makes sure you won't mess up anything.
-
@hek I have a quick question regarding the gw.saveState and consequently the gw.loadState instructions
As per the link and code you have mentioned, reproduced below:// EEPROM start address for mysensors library data #define EEPROM_START 0 // EEPROM location of node id #define EEPROM_NODE_ID_ADDRESS EEPROM_START // EEPROM location of parent id #define EEPROM_PARENT_NODE_ID_ADDRESS (EEPROM_START+1) // EEPROM location of distance to gateway #define EEPROM_DISTANCE_ADDRESS (EEPROM_PARENT_NODE_ID_ADDRESS+1) #define EEPROM_ROUTES_ADDRESS (EEPROM_DISTANCE_ADDRESS+1) // Where to start storing routing information in EEPROM. Will allocate 256 bytes. #define EEPROM_CONTROLLER_CONFIG_ADDRESS (EEPROM_ROUTES_ADDRESS+256) // Location of controller sent configuration (we allow one payload of config data from controller) #define EEPROM_FIRMWARE_TYPE_ADDRESS (EEPROM_CONTROLLER_CONFIG_ADDRESS+24) #define EEPROM_FIRMWARE_VERSION_ADDRESS (EEPROM_FIRMWARE_TYPE_ADDRESS+2) #define EEPROM_FIRMWARE_BLOCKS_ADDRESS (EEPROM_FIRMWARE_VERSION_ADDRESS+2) #define EEPROM_FIRMWARE_CRC_ADDRESS (EEPROM_FIRMWARE_BLOCKS_ADDRESS+2) #define EEPROM_LOCAL_CONFIG_ADDRESS (EEPROM_FIRMWARE_CRC_ADDRESS+2) // First free address for sketch static configurationI understand it translates to:
ADDRESS SIZE ALIAS 0X000 1 BYTE EEPROM_START, EEPROM_NODE_ID_ADDRESS 0X001 1 BYTE EEPROM_PARENT_NODE_ID_ADDRESS 0X002 1 BYTE EEPROM_DISTANCE_ADDRESS 0X003 256 BYTES EEPROM_ROUTES_ADDRESS 0X103 24 BYTES EEPROM_CONTROLLER_CONFIG_ADDRESS 0X11B 2 BYTES EEPROM_FIRMWARE_TYPE_ADDRESS 0X11D 2 BYTES EEPROM_FIRMWARE_VERSION_ADDRESS 0X11F 2 BYTES EEPROM_FIRMWARE_BLOCKS_ADDRESS 0X121 2 BYTES EEPROM_FIRMWARE_CRC_ADDRESS 0X123 ??? EEPROM_LOCAL_CONFIG_ADDRESSSo it means when I perform these instructions:
lightStatus = state;
gw.saveState(0,state);In what specific address am I saving the data? The instruction itself says position zero, so am I saving to the first address 0x123 in this case???
Thanks in advance.
-
Sound good! How can I write/read values over 255 to the EEPROM. This takes more then one byte.
If I write 255, I get: 255 0 (place 0 place 1)
256 will give: 0 255
257 will give: 1 255
etc.Reading only reads the byte indicated with the function loadState()
Thanks in advance
Ralph
-
Sound good! How can I write/read values over 255 to the EEPROM. This takes more then one byte.
If I write 255, I get: 255 0 (place 0 place 1)
256 will give: 0 255
257 will give: 1 255
etc.Reading only reads the byte indicated with the function loadState()
Thanks in advance
Ralph
@bisschopsr I think you can use hw_writeConfigBlock/hw_readConfigBlock with the "right" address
-
Hi All,
Resolved this with a simple funtion splitting the value in byte long parts. Bit shifting and OR are a perfect fit for this :-).
The code:
void storeEeprom(int pos, int value) { // function for saving the values to the internal EEPROM // value = the value to be stored (as int) // pos = the first byte position to store the value in // only two bytes can be stored with this function (max 32.767) gw.saveState(pos, ((unsigned int)value >> 8 )); pos++; gw.saveState(pos, (value & 0xff)); } int readEeprom(int pos) { // function for reading the values from the internal EEPROM // pos = the first byte position to read the value from int hiByte; int loByte; hiByte = gw.loadState(pos) << 8; pos++; loByte = gw.loadState(pos); return (hiByte | loByte); }
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better 💗
Register Login