Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,14 +79,19 @@ and voltages above the selected range are rejected without an I2C write.
Saving is never automatic. Do not call it repeatedly or from a loop; the
datasheet does not specify the nonvolatile-memory endurance.

The I2C peripheral must be released before saving and restored afterward:
Release the I2C peripheral before saving, then restore it afterward. ESP8266 is
the exception because its software I2C core does not provide `Wire.end()`:

```cpp
#ifndef ESP8266
Wire.end();
#endif
bool saved = gp8403.saveToNVM(SDA, SCL);
Wire.begin();
```

On ESP8266, `saveToNVM()` takes control of SDA and SCL directly.

If your application uses custom pins, speed, or other bus settings, restore the
same configuration instead of using the parameterless `Wire.begin()` shown
above.
Expand Down
9 changes: 6 additions & 3 deletions examples/nvm_persistence/nvm_persistence.ino
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
*
* WARNING: NVM programming uses a special open-drain waveform, not a normal
* I2C transaction. Wire must be stopped before saveToNVM() and restarted
* afterward.
* afterward. ESP8266 is the exception because it does not provide Wire.end().
*
* WARNING: NVM programming always uses the GP8403's hardcoded 0x58 address.
* It cannot save a device configured at another I2C address.
Expand Down Expand Up @@ -60,9 +60,12 @@ void setup() {
waitForCommand('S');

// saveToNVM() temporarily controls SDA and SCL directly as open-drain GPIO.
// Stop Wire first so the I2C peripheral releases those pins. If your project
// uses custom pins or bus settings, restore that same configuration below.
// Stop Wire first. ESP8266's software I2C implementation is the exception
// because it does not provide Wire.end(). If your project uses custom pins
// or bus settings, restore that same configuration below.
#ifndef ESP8266
Wire.end();
#endif
bool saved = gp8403.saveToNVM(SDA, SCL);
Wire.begin();

Expand Down
2 changes: 2 additions & 0 deletions hw_tests/03_nvm_persistence/03_nvm_persistence.ino
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,9 @@ char waitForCommand() {
}

bool saveNVM() {
#ifndef ESP8266
Wire.end();
#endif
bool saved = gp8403.saveToNVM(SDA, SCL);
Wire.begin();
return saved;
Expand Down
Loading