/* * i2c.c * * Created: 11/7/2012 7:18:23 PM * Author: kripperger */ #include #include #include "../config.h" #include "i2c.h" /* I2C clock in Hz */ #define SCL_CLOCK 100000L /************************************************************************* Initialization of the I2C bus interface. Need to be called only once *************************************************************************/ void i2c_init(void) { /* initialize TWI clock: 100 kHz clock, TWPS = 0 => prescaler = 1 */ TWSR = 0; /* no prescaler */ TWBR = ((F_CPU/SCL_CLOCK)-16)/2; /* must be > 10 for stable operation */ }/* i2c_init */ /************************************************************************* Issues a start condition and sends address and transfer direction. return 0 = device accessible, 1= failed to access device *************************************************************************/ unsigned char i2c_start(unsigned char address) { uint8_t twst; // send START condition TWCR = (1<