Dear all,
this my write operation c code i'm using CodeVision TWI interfacing protocol, what in my code doesn't make it work?
void WriteMemo(unsigned char ADCr, unsigned char LSB_add, unsigned char MSB_add)
{
TWCR = (1<<TWINT) | (1<<TWSTA) | (1<<TWEN); // start signal
TWDR = 0xA0; // device 0 address, write operation
TWCR = (1<<TWINT) | (1<<TWEN);
while(!(TWCR & (1<<TWINT))); // wait for ACK
TWDR = MSB_add; // send 1st byte of address
TWCR = (1<<TWINT) | (1<<TWEN); // clear INT falg to apply operation
while(!(TWCR & (1<<TWINT)));
TWDR = LSB_add; // send 2nd byte of address
TWCR = (1<<TWINT) | (1<<TWEN);
while(!(TWCR & (1<<TWINT)));
TWDR = ADCr; // send data
TWCR = (1<<TWINT) | (1<<TWEN);
while(!(TWCR & (1<<TWINT)));
TWCR = (1<<TWINT) | (1<<TWEN) | (1<<TWSTO);
}
also i enabled I-bit in SREG , and i intialized Register TWCR with 0x40[/quote]