help with TWI interfacing

Status
Not open for further replies.

shebo

Member level 2
Joined
Mar 28, 2006
Messages
42
Helped
5
Reputation
10
Reaction score
3
Trophy points
1,288
Location
do you ever care?
Activity points
1,553
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]
 

Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…