]> git.donarmstrong.com Git - tmk_firmware.git/blobdiff - keyboard/ergodox/twimaster.c
Change I2C clock speed to 444 kHz
[tmk_firmware.git] / keyboard / ergodox / twimaster.c
index a4dc5c11ad2525c6574cfa41b3384eead29f54ff..f91c08e6e4e83ccd0fc570848d82845a43b0c9f5 100644 (file)
 
 /* define CPU frequency in Mhz here if not defined in Makefile */
 #ifndef F_CPU
-#define F_CPU 4000000UL
+#define F_CPU 16000000UL
 #endif
 
 /* I2C clock in Hz */
-#define SCL_CLOCK  100000L
+#define SCL_CLOCK  400000L
 
 
 /*************************************************************************
 *************************************************************************/
 void i2c_init(void)
 {
-  /* initialize TWI clock: 100 kHz clock, TWPS = 0 => prescaler = 1 */
+  /* initialize TWI clock
+   * minimal values in Bit Rate Register (TWBR) and minimal Prescaler
+   * bits in the TWI Status Register should give us maximal possible
+   * I2C bus speed - about 444 kHz
+   *
+   * for more details, see 20.5.2 in ATmega16/32 secification
+   */
   
-  TWSR = 0;                         /* no prescaler */
-  TWBR = ((F_CPU/SCL_CLOCK)-16)/2;  /* must be > 10 for stable operation */
+  TWSR = 0;     /* no prescaler */
+  TWBR = 10;    /* must be >= 10 for stable operation */
 
 }/* i2c_init */