This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

The data send by master is not received at slave end.

hello,

I have written this I2C bit bang code for eZ430-rf2500. I am able to write the code..I have checked it on logic analyzer. But this code is not read by the slave.

I think the problem is in some condition ..Please someone help me.. I am posting the main function  and write function for master and read function for slave.

//   MASTER CODE


void main(void)
{
WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer
BCSCTL1 = CALBC1_8MHZ;
DCOCTL = CALBC1_8MHZ;
Init();
while(1)
{

start();
write(0x26);
stop();

for (int i=0;i<0xff;i++)
for(int j=0;j<0x44;j++);
}
}

unsigned char write(char c)
{
unsigned char ack=0x00;
for(int i=0;i<8;i++)
{
SCL_Low();
if(c & 0x80)
SDA_High();
else
SDA_Low();
c= c<<1;
SCL_High();
}
SCL_Low();
//Read Ack
delay();
SDA_High();

SCL_High();
if(P2IN == 0x00)
{
ack = 0;    // No acknowledgement is there
}
else
{
ack = 1; // Acknowledgement is there
}
SCL_Low();
return(ack);
}

//    SLAVE CODE



void main(void)
{
WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer
BCSCTL1 = CALBC1_1MHZ;
DCOCTL = CALBC1_1MHZ;
P2SEL &= ~SDA;
P2SEL &= ~SCL;
P2DIR &= ~SDA;
P2DIR &= ~SCL;

while(1)
{
while((P2IN & SDA) && ( P2IN & SCL));
while((P2IN & SDA)==0x02);
read_addr();
}
}

char read_addr()
{
SDA_High();
char a=0x01;
char c;
for(int i=0;i<8;i++)
{
while((P2IN & SCL) ==0x00);
c = c<<1;
if(P2IN & SDA)
c |= 0x01;
else
c &= ~0x01;
//while((P2IN & SCL) == 0x04);
}
while((P2IN & SCL) == 0x04);
if(c == 0x26)
{
a=0x00;
SDA_Low();
}
// while((P2IN & SCL) == 0x00);
return(a);
}

Please someone help me. I am in urgent need for this code for my project.


**Attention** This is a public forum