10 #include <compat/twi.h>
16 #define F_CPU 16000000UL
20 #define SCL_CLOCK 400000L
31 TWBR = ((F_CPU/SCL_CLOCK)-16)/2;
45 TWCR = (1<<TWINT) | (1<<TWSTA) | (1<<TWEN);
48 while(!(TWCR & (1<<TWINT)));
51 twst = TW_STATUS & 0xF8;
52 if ( (twst != TW_START) && (twst != TW_REP_START))
return 1;
56 TWCR = (1<<TWINT) | (1<<TWEN);
59 while(!(TWCR & (1<<TWINT)));
62 twst = TW_STATUS & 0xF8;
63 if ( (twst != TW_MT_SLA_ACK) && (twst != TW_MR_SLA_ACK) )
return 1;
84 TWCR = (1<<TWINT) | (1<<TWSTA) | (1<<TWEN);
87 while(!(TWCR & (1<<TWINT)));
90 twst = TW_STATUS & 0xF8;
91 if ( (twst != TW_START) && (twst != TW_REP_START))
continue;
95 TWCR = (1<<TWINT) | (1<<TWEN);
98 while(!(TWCR & (1<<TWINT)));
101 twst = TW_STATUS & 0xF8;
102 if ( (twst == TW_MT_SLA_NACK )||(twst ==TW_MR_DATA_NACK) )
105 TWCR = (1<<TWINT) | (1<<TWEN) | (1<<TWSTO);
108 while(TWCR & (1<<TWSTO));
140 TWCR = (1<<TWINT) | (1<<TWEN) | (1<<TWSTO);
143 while(TWCR & (1<<TWSTO));
161 TWCR = (1<<TWINT) | (1<<TWEN);
164 while(!(TWCR & (1<<TWINT)));
167 twst = TW_STATUS & 0xF8;
168 if( twst != TW_MT_DATA_ACK)
return 1;
181 TWCR = (1<<TWINT) | (1<<TWEN) | (1<<TWEA);
182 while(!(TWCR & (1<<TWINT)));
196 TWCR = (1<<TWINT) | (1<<TWEN);
197 while(!(TWCR & (1<<TWINT)));