I2C (I squared C) bus ===================== I2C is a relatively slow (100kHz), serial bus. Multiple devices can be attached to the bus, each one has an address (factory defined), and each device only responds to its own address. The bus is open collector, that is every device on the bus can only pull a line low, the lines must have a pullup resistor. Bus contention is resolved by each device monitoring the bus when it is writing - if it writes a 1 and sees a 0 then it knows there has been a collision with another device on the bus and it immediately stops transmitting. The device it collided with doesn't even notice the collision. In normal implementations, the guy who generates the clock controls the bus. For microcontroller implementations, the microcontroller is both the boss and the clock generator. Writing to the bus is straightforward - issue a start, send the address+write, send the data, check that the recipient acknowledged it. Reading is similar - issue a start, send the address+read request, read the data, then issue an acknowledgement. This is all taken care of by the library i2c.c which uses polling, not interrupts. There are four functions: i2c_timerproc must be called every 10 milliseconds - it is used to timeout any stuck requests. read_i2c_device - reads one or more bytes from the I2C device at the supplied address read_i2c_device - writes one or more bytes to the specified I2C device addresses write_read_i2c_device - Write 1 or more bytes to an I2C device followed by a read without releasing the bus. After any transaction, check for a return code of 0 = success. Note that you MUST set up the bus speed, see the details in i2c.h There is one gotcha: Addresses are 7 bit D7..D1 with R/W on the bottom, D0. In the datasheet it is never clear whether the address is shown shifted left by 1 bit or not.