|
Hi
You can check the ACK flag after writing the I2C data and report 1 or 0 on EP0 endpoint and check what value you are receiving on the EP0.
For Eg check the following code:
BYTE y;
y=0;
while (I2CS & bmSTOP);
// set the START bit and write the address
I2CS = bmSTART;
I2DAT = SETUPDAT[5];
while (!(I2CS & bmDONE));
while (!(I2CS & bmACK));
// write at requested address
I2DAT = SETUPDAT[3];
while (!(I2CS & bmDONE));
while (!(I2CS & bmACK));
I2DAT = SETUPDAT[2];
while (!(I2CS & bmDONE));
while (!(I2CS & bmACK));
// write at requested byte
I2DAT = SETUPDAT[4];
while (!(I2CS & bmDONE));
while (!(I2CS & bmACK));
I2CS = bmSTOP;
y=1;
EP0BUF[0]=0xFF;
EP0BCH=0;
EP0BCL=1;
In the above code snippet, for IN transfer you will receive 0xFF on EP0 if all the I2C tranfers complete otherwise the program will get stuck in loop: while (!(I2CS & bmACK));
and the IN transfer would fail.
I hope this post answers your question.
Thanks
Nikhil
|