diff --git a/README.md b/README.md index b09e025..3520206 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/examples/nvm_persistence/nvm_persistence.ino b/examples/nvm_persistence/nvm_persistence.ino index 5ef7e2a..cc56ea3 100644 --- a/examples/nvm_persistence/nvm_persistence.ino +++ b/examples/nvm_persistence/nvm_persistence.ino @@ -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. @@ -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(); diff --git a/hw_tests/03_nvm_persistence/03_nvm_persistence.ino b/hw_tests/03_nvm_persistence/03_nvm_persistence.ino index 0e14f19..e7e39e2 100644 --- a/hw_tests/03_nvm_persistence/03_nvm_persistence.ino +++ b/hw_tests/03_nvm_persistence/03_nvm_persistence.ino @@ -127,7 +127,9 @@ char waitForCommand() { } bool saveNVM() { +#ifndef ESP8266 Wire.end(); +#endif bool saved = gp8403.saveToNVM(SDA, SCL); Wire.begin(); return saved;