Skip to content
Tiogaplanet edited this page Oct 9, 2018 · 3 revisions

MiP has a built-in electrically erasable programmable read-only memory (EEPROM) which can be read from or written to. The EEPROM provides up to 16 bytes of accessible memory. MiP's internal memory addresses are 0x20-0x2F. To implement these functions, only an offset need be provided as in 0x00-0x0F.


setUserData()

void setUserData(uint8_t addressOffset, uint8_t userData)

Description

Stores one byte of user data to the offset specified. Valid offsets are 0x00-0x0F.

Parameters

  • addressOffset is the address offset at which to write the user's data.
  • userData is the one byte of data to be written to EEPROM.

Returns

Nothing

Example

#include <mip_esp8266.h>

MiP           mip;

// Use an offset between 0x00 and 0x0F.
const uint8_t eepromAddressOffset = 0x00;

// Try different hex values here to see them stored and
// recovered from EEPROM.
uint8_t       secretPassword = 0x0D;

void setup() {
  // First need to initialize the serial connection with MiP.
  bool connectResult = mip.begin();
  if (!connectResult) {
    Serial.println(F("Failed connecting to MiP!"));
    return;
  }

  Serial.println(F("ReadWriteEeprom.ino - Writes data to EEPROM and reads it back."));

  Serial.print(F("Original password: "));
  Serial.println(secretPassword, HEX);

  // Power-off MiP, comment out this line, recompile and load to the ProMini-Pack to see EEPROM
  // data preserved across power cycles.
  mip.setUserData(eepromAddressOffset, secretPassword);

  // "Scramble" the secret password.
  secretPassword = 0xFF;
  Serial.print(F("Scrambled password: "));
  Serial.println(secretPassword, HEX);

  Serial.print(F("Recovered password: "));
  Serial.print(mip.getUserData(eepromAddressOffset), HEX);
}

void loop() {
}

getUserData()

uint8_t getUserData(uint8_t addressOffset)

Description

Reads one byte of user data from the address offset specified. Valid addresses are 0x00-0x0F.

Parameters

  • addressOffset is the address at which to read stored data.

Returns

  • The contents of the EEPROM read from the given address offset.

Example

#include <mip_esp8266.h>

MiP           mip;

// Use an offset between 0x00 and 0x0F.
const uint8_t eepromAddressOffset = 0x00;

// Try different hex values here to see them stored and
// recovered from EEPROM.
uint8_t       secretPassword = 0x0D;

void setup() {
  // First need to initialize the serial connection with MiP.
  bool connectResult = mip.begin();
  if (!connectResult) {
    Serial.println(F("Failed connecting to MiP!"));
    return;
  }

  Serial.println(F("ReadWriteEeprom.ino - Writes data to EEPROM and reads it back."));

  Serial.print(F("Original password: "));
  Serial.println(secretPassword, HEX);

  // Power-off MiP, comment out this line, recompile and load to the ProMini-Pack to see EEPROM
  // data preserved across power cycles.
  mip.setUserData(eepromAddressOffset, secretPassword);

  // "Scramble" the secret password.
  secretPassword = 0xFF;
  Serial.print(F("Scrambled password: "));
  Serial.println(secretPassword, HEX);

  Serial.print(F("Recovered password: "));
  Serial.print(mip.getUserData(eepromAddressOffset), HEX);
}

void loop() {
}
Clone this wiki locally