Skip to content

Commit 594bab8

Browse files
committed
Use Wire.setClock to set I2C frequency when using Arduino 1.5.7 or above
See: arduino/Arduino#1912
1 parent 30ee5e9 commit 594bab8

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

I2C.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,11 @@ static const uint8_t I2C_TIMEOUT = 100; // Used to check for errors in I2C commu
2424

2525
void initI2c() {
2626
Wire.begin();
27-
TWBR = ((F_CPU / 400000L) - 16) / 2; // Set I2C frequency to 400kHz
27+
#if ARDUINO >= 157
28+
Wire.setClock(400000UL); // Set I2C frequency to 400kHz
29+
#else
30+
TWBR = ((F_CPU / 400000UL) - 16) / 2; // Set I2C frequency to 400kHz
31+
#endif
2832
}
2933

3034
uint8_t i2cWrite(uint8_t address, uint8_t registerAddress, uint8_t data, bool sendStop /*= true*/) {

0 commit comments

Comments
 (0)