Skip to content

Commit 2bc2e85

Browse files
authored
Merge pull request adafruit#3 from ladyada-eagleclaw/fix-wire-end-portability
Fix NVM example on ESP8266
2 parents f31a85e + 6c7cf4c commit 2bc2e85

3 files changed

Lines changed: 14 additions & 4 deletions

File tree

README.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,14 +79,19 @@ and voltages above the selected range are rejected without an I2C write.
7979
Saving is never automatic. Do not call it repeatedly or from a loop; the
8080
datasheet does not specify the nonvolatile-memory endurance.
8181

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

8485
```cpp
86+
#ifndef ESP8266
8587
Wire.end();
88+
#endif
8689
bool saved = gp8403.saveToNVM(SDA, SCL);
8790
Wire.begin();
8891
```
8992

93+
On ESP8266, `saveToNVM()` takes control of SDA and SCL directly.
94+
9095
If your application uses custom pins, speed, or other bus settings, restore the
9196
same configuration instead of using the parameterless `Wire.begin()` shown
9297
above.

examples/nvm_persistence/nvm_persistence.ino

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
*
1111
* WARNING: NVM programming uses a special open-drain waveform, not a normal
1212
* I2C transaction. Wire must be stopped before saveToNVM() and restarted
13-
* afterward.
13+
* afterward. ESP8266 is the exception because it does not provide Wire.end().
1414
*
1515
* WARNING: NVM programming always uses the GP8403's hardcoded 0x58 address.
1616
* It cannot save a device configured at another I2C address.
@@ -60,9 +60,12 @@ void setup() {
6060
waitForCommand('S');
6161

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

hw_tests/03_nvm_persistence/03_nvm_persistence.ino

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,9 @@ char waitForCommand() {
127127
}
128128

129129
bool saveNVM() {
130+
#ifndef ESP8266
130131
Wire.end();
132+
#endif
131133
bool saved = gp8403.saveToNVM(SDA, SCL);
132134
Wire.begin();
133135
return saved;

0 commit comments

Comments
 (0)