Is there any way to change I2C speed from 100K to 400K in one's own code, i.e. without modifying libraries/Wire/utility/twi.h?
I would like to ensure that if someone else later builds my code having re-downloaded the libraries, they don't unknowingly revert to 100K speed.
Alternatively, is there any way to detect in my code what speed I2C is running at - either at runtime, or, ideally, during the build process (I build from edam's Arduino makefile).
that code clears the lowest two bits in the register, so TWSR & 0x03 is always 0 and 4 ^ 0 is 1 as you would expect. If you get the result 142, TWSR must have bit 0 set but I see absolutely no reason for that. To test, don't divide by 1000 in the print. What do you get then?
(You do know that ^ means XOR, not exponent, right?)
Although I actually do know I didn't realize, I definitely switch between languages too often. That's my error, please excuse. The good news is that just the calculation of the set speed is wrong, the speed itself is correct.