EEPROM put with part of an array

A simple EEPROM library question ...

I have data being sent to me as array of bytes.

byte data[6] = {0x10, 0x00, 0x1A, 0x1B, 0x1C, 0x1D};
//	DATABYTE0 = High memory address
//	DATABYTE1 = LOW memory address
//	DATABYTE2 = memory databyte1 to write
//	DATABYTE3 = memory databyte2 to write
//	DATABYTE4 = memory databyte3 to write
//	DATABYTE5 = memory databyte4 to write

I want to write the last 4 bytes into EEPROM at the address indicated by the first two bytes. So some psuedo code ...

  // get the destination address, will be 0x1000
  uint16_t address = data[0] << 8 + data[1];

  EEPROM.put(address, ??);

Do I need to copy the last 4 bytes of can I somehow have some type of struct that only accesses those last 4 bytes ?

Or just old school and iterate over the last 4 bytes and use EEPROM.update ?

That's probably easiest unless you're willing to change the datatype that holds the data.

1 Like

Will EEPROM.put(someAddress, &someArray[2]) not work?

put() takes a reference, not a pointer.

Looking in 'eeprom.h' (note lower case name) I found this. It might be worth a try, I've never used it:

/** \ingroup avr_eeprom
    Update a block of \a __n bytes to EEPROM address \a __dst from \a __src.
    \note The argument order is mismatch with common functions like strcpy().
 */
void eeprom_update_block (const void *__src, void *__dst, size_t __n);
1 Like

Thanks, stupid me.

Thanks, I think I will just stick with old school iteration and use the EEPROM.update

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.