From a530b6a3d46385586e6ece1202ee505c09157150 Mon Sep 17 00:00:00 2001 From: victorpv Date: Mon, 11 Sep 2017 22:49:03 -0500 Subject: [PATCH] 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. --- STM32F1/libraries/Wire/Wire.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/STM32F1/libraries/Wire/Wire.cpp b/STM32F1/libraries/Wire/Wire.cpp index 3f5f161..a026e2e 100644 --- a/STM32F1/libraries/Wire/Wire.cpp +++ b/STM32F1/libraries/Wire/Wire.cpp @@ -97,8 +97,10 @@ void HardWire::setClock(uint32_t frequencyHz) dev_flags &= ~I2C_FAST_MODE;// clear FAST_MODE bit break; } - i2c_disable(sel_hard); - i2c_master_enable(sel_hard, dev_flags); + if (sel_hard->regs->CR1 & I2C_CR1_PE){ + i2c_disable(sel_hard); + i2c_master_enable(sel_hard, dev_flags); + } } HardWire Wire(1);