Eeprom usage



  • Hi.
    How mySensors usage eeprom memory?
    How many bytes and with addresses?
    I would like use eeprom memory to own application but I don't know with address will be free.

    Thx.
    Pawel


  • Admin

    You'll find the addresses used here:
    https://github.com/mysensors/Arduino/blob/master/libraries/MySensors/MySensor.h#L44

    If 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 configuration
    

    I 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_ADDRESS
    

    So 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.


  • Admin

    0x123

    Yes, that sounds about right.



  • 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);
    }
    

Log in to reply
 

Suggested Topics

  • 4
  • 2
  • 9
  • 20
  • 14
  • 4

0
Online

11.4k
Users

11.1k
Topics

112.6k
Posts