Skip to content

Commit a530b6a

Browse files
authored
Update Wire.cpp
Adds a check to verify if the port had been already enabled, and only in that case disables/re-enables the port. This also solves the issue of setClock being called after begin(), but doesn't not enable the port if begin() had not been called yet.
1 parent 799f2b3 commit a530b6a

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

STM32F1/libraries/Wire/Wire.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,10 @@ void HardWire::setClock(uint32_t frequencyHz)
9797
dev_flags &= ~I2C_FAST_MODE;// clear FAST_MODE bit
9898
break;
9999
}
100-
i2c_disable(sel_hard);
101-
i2c_master_enable(sel_hard, dev_flags);
100+
if (sel_hard->regs->CR1 & I2C_CR1_PE){
101+
i2c_disable(sel_hard);
102+
i2c_master_enable(sel_hard, dev_flags);
103+
}
102104
}
103105

104106
HardWire Wire(1);

0 commit comments

Comments
 (0)