anupam19 / u8glib

Automatically exported from code.google.com/p/u8glib
Other
0 stars 0 forks source link

I2C 400KHz Option #303

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Option: U8G_I2C_OPT_FAST (alread addet to u8g.h)

If U8G_I2C_OPT_FAST is set then
TWBR = F_CPU/(2*400000)-8;

from: http://forum.arduino.cc/index.php?topic=286055.new#new

Original issue reported on code.google.com by olikr...@gmail.com on 20 Dec 2014 at 8:27

GoogleCodeExporter commented 9 years ago
This option has been implemented for the Due and for SSD1306/SH1106.

Original comment by olikr...@gmail.com on 21 Dec 2014 at 7:37

GoogleCodeExporter commented 9 years ago
for avr, this is the change:
void u8g_i2c_init(uint8_t options)
{
  /*
  TWBR: bit rate register
  TWSR: status register (contains preselector bits)

  prescalar
    0       1
    1       4
    2       16
    3       64

  f = F_CPU/(16+2*TWBR*prescalar)

  F_CPU = 16MHz
    TWBR = 152;
    TWSR = 0;
    --> 50KHz

    TWBR = 72;
    TWSR = 0;
    --> 100KHz

    TWBR = 12;
    TWSR = 0;
    --> 400KHz

    F_CPU/(2*100000)-8  --> calculate TWBR value for 100KHz
*/
  u8g_i2c_opt = options;
  TWSR = 0;
  if ( options & U8G_I2C_OPT_FAST )
  {
    TWBR = F_CPU/(2*400000)-8;
  }
  else
  {  
    TWBR = F_CPU/(2*100000)-8;
  }
  u8g_i2c_clear_error();
}

testing required

Original comment by olikr...@gmail.com on 21 Dec 2014 at 10:15

GoogleCodeExporter commented 9 years ago
works nicely with the Arduino Uno

Original comment by olikr...@gmail.com on 21 Dec 2014 at 2:03

GoogleCodeExporter commented 9 years ago
test ok

Original comment by olikr...@gmail.com on 21 Dec 2014 at 5:00

GoogleCodeExporter commented 9 years ago
It works fine at 400khz on Uno.

Original comment by honda.po...@gmail.com on 21 Dec 2014 at 10:44