void i2c_init()
{
- TWAR = BMC_ADDR;
- TWCR &= ~(1<<TWSTA)|(1<<TWSTO);
- TWCR|= (1<<TWEA) | (1<<TWEN)|(1<<TWIE);
+ TWAR = BMC_ADDR & 0xfe;
+ TWDR = 0x00;
+ TWCR &= ~((1<<TWSTA) | (1<<TWSTO));
+ TWCR |= ((1<<TWEA) | (1<<TWEN) | (1<<TWIE));
+ printf("Status: 0x%02x\n", TW_STATUS);
+ PORTC = 0x03;
}
-ISR (TWI_vect)
+ISR (TWI_vect, ISR_BLOCK)
{
- printf("Interrupt, Status: %02x!\n", TW_STATUS);
+ printf("Interrupt, Status: 0x%02x, Data: 0x%02x!\n", TW_STATUS, TWDR);
switch (TW_STATUS) {
default:
- TWCR_RESET;
+ TWCR_ACK;
break;
}
}