Closed RobTillaart closed 2 years ago
From ATMEL328 datasheet
Page 223
page 244 - 21.9.3 - TWSR – TWI Status Register
TWI.C
// initialize twi prescaler and bit rate
cbi(TWSR, TWPS0);
cbi(TWSR, TWPS1);
TWBR = ((F_CPU / TWI_FREQ) - 16) / 2;
In AVR the prescaler is therefor always 1 (hence the formula) As we need to set the SCL to 30 Kbit or even 25 or 20 Kbit we can calculate if this is easier with changed TWSR
TWBR = ((F_CPU / TWI_FREQ) - 16) / (2 * prescaler);
Spreadsheet
|
See: https://github.com/adafruit/Adafruit_BusIO/pull/104
If the prescaler was not 0 just setting the TWBR register low is not always enough. Need to explicitly set prescaler too.
And set the prescaler back too.