Programming I2C/TWI Using AVR Microcontroller
Programming I2C/TWI Using AVR Microcontroller
Jamshoro
Department of Telecommunication Engineering
By:
Registers
TWBR (TWI Bitrate Register)
To TWI Clock Frequency
24
16)
Programming Steps
Address:
b0=0
b0=1
// Write Operation
// Read Operation
// start TWI
// wait till op. finish
TWDR=0xD0;
while(TWCR & (1<<TWINT) == 0);
// Address + Write(0)
// wait till tx completes
TWDR=0xF0;
while(TWCR & (1<<TWINT) == 0);
// Data
// wait till tx completes
TWCR |= (1<<TWSTO);
while(1);
// Stop TWI
return 0;
}