it's all in the title ; I'm developping a library and use *TwoWire pointers in this library ; but I am using an external library that calls Wire.begin(). I've seen something about TWCR register in arduino but I don't know what it is exaclty.
Thanks in advance :)
1 Answer 1
What you are interested in is this bit of the Wire library:
TWCR = _BV(TWEN) | _BV(TWIE) | _BV(TWEA);
The important bit is the TWEN
bit - TwoWire ENable.
If that bit is set in the TWCR register than Wire.begin() has been called already and you don't need to call it again:
if (TWCR & _BV(TWEN) == 0) {
Wire.begin();
}
However, it really doesn't matter if you call it multiple times.
-
1other thing is if you do setFrequency(400000L) and then some other library calls Wire.begin()2018年06月16日 13:49:16 +00:00Commented Jun 16, 2018 at 13:49
-
Just to precise, it was to avoid such problems github.com/esp8266/Arduino/issues/2607 I don't know if it concerns me but I'll see with the prototypeStorca– Storca2018年06月20日 10:02:39 +00:00Commented Jun 20, 2018 at 10:02
-
@Storca Note that that's for a completely different architecture, so the "fix" I detail above has no relevance to it. The proper place for it to be fixed would be in the Wire library. We do it properly chipKIT: github.com/chipKIT32/chipKIT-core/blob/master/pic32/libraries/… - only allow begin to run the first time it's called.Majenko– Majenko2018年06月20日 10:06:29 +00:00Commented Jun 20, 2018 at 10:06