This application note (PDF) from Atmel describes the implementation of a TWI master:
The Two-wire serial Interface (TWI) is compatible with Philips’ I2C protocol. The bus was developed to allow simple, robust and cost effective communication between integrated circuits in electronics. The strengths of the TWI bus includes the capability of addressing up to 128 devices on the same bus, arbitration, and the possibility to have multiple masters on the bus.
The Universal Serial Interface (USI) module on devices like Atmel ATmega169, ATtiny26, and ATtiny2313 has a dedicated Two-wire mode. The USI provides the basic hardware resources needed for synchronous serial communication. Combined with a minimum of control software, the USI allows higher transfer rates and uses less code space than solutions based on software only. This application note describes a TWI master implementation, in form of a full featured driver and an example of usage for this driver. The driver handles transmission according to both Standard mode (<100kbps) and Fast mode (<400kbps).