X-Git-Url: https://git.friedersdorff.com/?a=blobdiff_plain;f=keyboard%2Fergodox%2Ftwimaster.c;h=3f9ccb3c0737ac4d43697dc639db5bd8076f8190;hb=HEAD;hp=f91c08e6e4e83ccd0fc570848d82845a43b0c9f5;hpb=57c6b597ead6a98ddaade97d66de55928a4fb2a2;p=max%2Ftmk_keyboard.git diff --git a/keyboard/ergodox/twimaster.c b/keyboard/ergodox/twimaster.c index f91c08e6..3f9ccb3c 100644 --- a/keyboard/ergodox/twimaster.c +++ b/keyboard/ergodox/twimaster.c @@ -1,7 +1,7 @@ /************************************************************************* * Title: I2C master library using hardware TWI interface * Author: Peter Fleury http://jump.to/fleury -* File: $Id: twimaster.c,v 1.3 2005/07/02 11:14:21 Peter Exp $ +* File: $Id: twimaster.c,v 1.4 2015/01/17 12:16:05 peter Exp $ * Software: AVR-GCC 3.4.3 / avr-libc 1.2.3 * Target: any AVR device with hardware TWI * Usage: API compatible with I2C Software Library i2cmaster.h @@ -12,13 +12,13 @@ #include -/* define CPU frequency in Mhz here if not defined in Makefile */ +/* define CPU frequency in hz here if not defined in Makefile */ #ifndef F_CPU -#define F_CPU 16000000UL +#define F_CPU 4000000UL #endif /* I2C clock in Hz */ -#define SCL_CLOCK 400000L +#define SCL_CLOCK 100000L /************************************************************************* @@ -26,16 +26,10 @@ *************************************************************************/ void i2c_init(void) { - /* 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 - */ + /* initialize TWI clock: 100 kHz clock, TWPS = 0 => prescaler = 1 */ - TWSR = 0; /* no prescaler */ - TWBR = 10; /* must be >= 10 for stable operation */ + TWSR = 0; /* no prescaler */ + TWBR = ((F_CPU/SCL_CLOCK)-16)/2; /* must be > 10 for stable operation */ }/* i2c_init */