kaze
Newbie level 5
Hi there, I was using ATMEGA8535 and want to use it I2C, programming using ICC AVR. But I have a problem that I couldn't resolve. Help me pls..
Here is a part of my I2c program to send data I've made 3 sample program at the first time the number1, the number 2 and number 3 was the modification.
void twi_init(void)
{
TWCR= 0X00; //disable twi
TWBR= 0x7C; //set bit rate
TWSR= 0x02; //set prescale
TWAR= 0x9E; //set slave address
TWCR= 0x44; //enable twi
}
number1:
void send(unsigned char data)
{
TWDR = data;
TWCR = (1<<TWINT) | (1<<TWEN);
}
number2:
void send_data(unsigned char DATA)
{
while (!(TWCR & (1<<TWINT)))
{
TWDR = DATA;
TWCR = (1<<TWINT) | (1<<TWEN);
}
}
number3:
void send_data1()
{
do
{
TWCR = 0xC4;
if(TWSR==0x1A)
{
TWDR = 0x9E; //instruction
TWCR = (1<<TWINT) | (1<<TWEN);
}
}while(!(TWCR & (1<<TWINT)));
}
Is all of my program is wrong or my slave IC was damage? I really dunno know how to test it. I really out of idea...
I wanna ask is when we set TWINT to 1 then the TWINT flag = 0, or the TWINT and TWINT flag is the same?
Thank for u're feedback.
my regrads.
Here is a part of my I2c program to send data I've made 3 sample program at the first time the number1, the number 2 and number 3 was the modification.
void twi_init(void)
{
TWCR= 0X00; //disable twi
TWBR= 0x7C; //set bit rate
TWSR= 0x02; //set prescale
TWAR= 0x9E; //set slave address
TWCR= 0x44; //enable twi
}
number1:
void send(unsigned char data)
{
TWDR = data;
TWCR = (1<<TWINT) | (1<<TWEN);
}
number2:
void send_data(unsigned char DATA)
{
while (!(TWCR & (1<<TWINT)))
{
TWDR = DATA;
TWCR = (1<<TWINT) | (1<<TWEN);
}
}
number3:
void send_data1()
{
do
{
TWCR = 0xC4;
if(TWSR==0x1A)
{
TWDR = 0x9E; //instruction
TWCR = (1<<TWINT) | (1<<TWEN);
}
}while(!(TWCR & (1<<TWINT)));
}
Is all of my program is wrong or my slave IC was damage? I really dunno know how to test it. I really out of idea...
I wanna ask is when we set TWINT to 1 then the TWINT flag = 0, or the TWINT and TWINT flag is the same?
Thank for u're feedback.
my regrads.