#include #include #include // init master // // void init_twi_master (uint8_t twbr) { // set the scl TWBR = twbr; TWCR = _BV(TWEN); } // send data // // int main (void) { init_twi_master (13); DDRB = 0xFF; uint16_t sleep; uint8_t i = 1; while (1) { PORTB = ~TWSR; // send start TWCR = _BV(TWINT) | _BV(TWSTA) | _BV(TWEN); while (!(TWCR & _BV(TWINT))); PORTB = ~TWSR; // send the addr TWDR = (1<<1) | 0; TWCR = _BV(TWINT) | _BV(TWEN); while (!(TWCR & _BV(TWINT))); PORTB = ~TWSR; if ((TWSR & 0xF8) != TW_MT_SLA_ACK){ //error(TWSR, 0x01); } //while(1){ TWDR = i; TWCR = _BV(TWINT) | _BV(TWEN); while (!(TWCR & _BV(TWINT))); PORTB = ~TWSR; if((TWSR & 0xF8) != TW_MT_DATA_ACK){ //error(TWSR, 0x02); } // i++; //} // send stop TWCR = _BV(TWINT) | _BV(TWSTO) | _BV(TWEN) | _BV(TWEA); while( !(TWCR & _BV(TWSTO)) ); //while (!(TWCR & _BV(TWINT))); PORTB = ~TWSR; //sleep = 65535; //while(sleep--); //TWCR = TWCR & ~(_BV(TWEN)); i++; } return 0; }