Skip to content

Commit 9b1c895

Browse files
authored
Preserve custome SCL, SDA and Frequency when Wire.begin() called
Changed how default parameters are interpreted. Now calling `Wire.begin()` without parameters will reuse the current values instead of resetting them to the default values. This change was prompted when it was found than custom pin assignments were being lost. The standard Arduino library practice is to issue a `Wire.begin()` call inside each library that uses `Wire()`. If a custom pin assignment was used, when these libraries were init'd, they caused a failure when they re-assigned the SDA and SCL pins. Changing Frequency back to 100khz was not a fatal problem.
1 parent da6be57 commit 9b1c895

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

libraries/Wire/src/Wire.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,10 @@ class TwoWire: public Stream
7070
public:
7171
TwoWire(uint8_t bus_num);
7272
~TwoWire();
73-
void begin(int sda=-1, int scl=-1, uint32_t frequency=100000);
74-
void setClock(uint32_t);
73+
void begin(int sda=-1, int scl=-1, uint32_t frequency=0);
74+
//defaults bus:0 sda=SDA, scl=SCL, frequency =100khz via variant pins_arduino.h
75+
// bus:1 unspecified, emits Log_E()
76+
void setClock(uint32_t); // change bus clock without initing hardware
7577
void beginTransmission(uint16_t);
7678
uint8_t endTransmission(bool);
7779
uint8_t requestFrom(uint16_t address, uint8_t size, bool sendStop);
@@ -88,7 +90,7 @@ class TwoWire: public Stream
8890
bool getDump(){return _dump;}
8991
void dumpInts();
9092
void dumpI2C(){i2cDumpI2c(i2c);}
91-
size_t getClock();
93+
size_t getClock(); // current bus clock rate in hz
9294
void setTimeOut(uint16_t timeOutMillis);
9395
uint16_t getTimeOut();
9496
//
@@ -140,6 +142,7 @@ extern TwoWire Wire;
140142

141143

142144
/*
145+
V0.2.2 13APR2018 preserve custom SCL,SDA,Frequency when no parameters passed to begin()
143146
V0.2.1 15MAR2018 Hardware reset, Glitch prevention, adding destructor for second i2c testing
144147
*/
145148
#endif

0 commit comments

Comments
 (0)