Skip to content

Commit 7bf1e36

Browse files
author
oclyke
committed
prevent double-initialization of I2C IOM modules
sometimes Wire.begin is called multiple times in one sketch. the HAL does not appreciate this. so we block it
1 parent 512e67b commit 7bf1e36

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

libraries/Wire/src/Wire.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,16 @@
88
arduino::MbedI2C::MbedI2C(int sda, int scl) : _sda(sda), _scl(scl), usedTxBuffer(0) {}
99

1010
void arduino::MbedI2C::begin() {
11-
master = new mbed::I2C((PinName)_sda, (PinName)_scl);
11+
if(!master){
12+
master = new mbed::I2C((PinName)_sda, (PinName)_scl);
13+
}
1214
}
1315

1416
void arduino::MbedI2C::begin(uint8_t slaveAddr) {
1517
#ifdef DEVICE_I2CSLAVE
16-
slave = new mbed::I2CSlave((PinName)_sda, (PinName)_scl);
18+
if(!slave){
19+
slave = new mbed::I2CSlave((PinName)_sda, (PinName)_scl);
20+
}
1721
slave->address(slaveAddr << 1);
1822
slave_th.start(mbed::callback(this, &arduino::MbedI2C::receiveThd));
1923
#endif

0 commit comments

Comments
 (0)