// 2 Wire Bus initialization // Generate Acknowledge Pulse: On // 2 Wire Bus Slave Address: TWI_ADDRESS // General Call Recognition: On // Bit Rate: 400,000 kHz TWSR=0x00; TWBR=0x0C; TWAR=(TWI_ADDRESS<<1)|0x01; TWCR=0x45; // 2 Wire bus interrupt service routine interrupt [TWI] void twi_isr(void) { switch((TWSR&0xF8)) { // START has been transmitted case 0x08: // Repeated START has been transmitted case 0x10: // Set TWI busy flag twi_flag_busy=1; // Write slave address and W to data field TWDR=(twi_message_t[twi_message_index][0x00]<<1)&0xFE; // Send address TWCR=0xC5; // TWINT, TWEA, TWEN, TWIE break; // Arbitration lost case 0x38: // Set TWI transmit flag twi_flag_t=1; // Abort this try TWCR=0xC5; // TWINT, TWEA, TWEN, TWIE break; // SLA+W has been tramsmitted and ACK received case 0x18: // Reset message part twi_message_part=0x01; // Write data to data field TWDR=twi_message_t[twi_message_index][twi_message_part]; // Send data TWCR=0xC5; // TWINT, TWEA, TWEN, TWIE break; // Data byte has been tramsmitted and ACK received case 0x28: // Continue to send message if necessary if((twi_message_part