hi
I am trying to interface between attiny2313a with pcf8563 using i2c protocol.I am facing the problem with ACK ,where the attiny2313a is writing the address(0xA2) .
The ACK pulse is not going fully high, in between only the pulse is pulled low and after that one extra pulse is generated for which, i didn't write any code.I am working on this problem for many days.
The waveform and the code is attached below.
*********CODE**********
/****i2c declarations***********/
#define HDEL _delay_us(60);
#define QDEL _delay_us(30);
#define SDA PORTB5
#define SCL PORTB7
#define PORT PORTB
//SCL
#define SCL_OUT DDRB|=(1<<SCL)
#define SCL_HI PORTB|=(1<<SCL);
#define SCL_LI PORTB&=~(1<<SCL);
//SDA
#define SDA_OUT DDRB|=(1<<SDA);
#define SDA_IN DDRB&=~(1<<SDA);
#define SDA_HI PORTB|=(1<<SDA);
#define SDA_LI PORTB&=~(1<<SDA);
/*******I2C DECLARATION END ****************/
int main(void)
{
unsigned char loopcounter,addr;
unsigned char testbuff[30];
usart_init();
//i2c init
SDA_OUT;QDEL;
SCL_OUT;QDEL;
while(1)
{
//i2c start
SDA_HI;QDEL;
SCL_HI;HDEL;
SDA_LI;QDEL;
SCL_LI;HDEL;
//i2c write address
addr=0xA2;
for(loopcounter=0;loopcounter<8;loopcounter++)
{
if(addr & 0x80)
{
SDA_HI;
}
else
{
SDA_LI;
}
QDEL;
SCL_HI;
HDEL;
SCL_LI;
QDEL;
addr<<=1;
}
//ACK FOR WRITE BYTE
SDA_HI;QDEL;
SDA_IN;QDEL;
SCL_HI;HDEL;
if((PORT>>SDA) & 1)
sprintf( testbuff,"failed wr\n\r");
else
sprintf( testbuff,"success wr\n\r");
SCL_LI;QDEL;
SDA_OUT;QDEL;//CHECK THEM PROPERLY
//i2c_stop
SDA_LI;QDEL;
SCL_HI;QDEL;
SDA_HI;HDEL;
_delay_ms(1000);
usart_string( testbuff);
usart_string("end\n\r");
}
}