Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

help with TWI interfacing

Status
Not open for further replies.

shebo

Member level 2
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.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top