Hi PetrM,
Thanks for your reply.
Find the algorithm below.....
1. Set the destination address using IO_IOCTL_I2C_SET_DESTINATION_ADDRESS command
2. Initiate start and send I2C bus address using fwrite(&mem,1,0,fd)
3. Check for the acknowledgement using (I2C_OK == ioctl (fd, IO_IOCTL_FLUSH_OUTPUT, ¶m)).
4. If ACK is High set the Dev_Flag and Give IO_IOCTL_FLUSH_OUTPUT and issue the STOP condition using IO_IOCTL_I2C_STOP.
5. Else ACK is LOW clear the Dev_flag and issue the STOP condition.
If the Dev_Flag is high proceed I2C read operation
else again check for the devive existance.
I2C Read
-------------
1. Set the Destination address
2. Get the destination address
3. Set the master to Master Receive mode using IO_IOCTL_I2C_SET_RX_REQUEST command, param is number of bytes to be read
4. Read operation
do
{
result = fread (ReceiveBuffer + result , 1, tempNoOfBytesToBeRead , fd);
Count++;
if(Count == 10)
{
Count = 0;
if(result == 0) /*If there is no valid reply from the slave device */
{
Dev_flag = 0;
printf("\n %d %d \n",Count,result);
break;
}
}
printf("\n result %d \n",result);
tempNoOfBytesToBeRead = tempNoOfBytesToBeRead - result;
} while (tempNoOfBytesToBeRead != 0);
5. Check whether all the byte transfer are completed by IO_IOCTL_FLUSH_OUTPUT command
6. Send a STOP condition.
Note: Our system is working properly untill we get the proper response from the slave device.Once if the communication is lost between the master and slave,in slave the I2C bus is getting released (HIGH),but in MCF if we send IO_IOCTL_FLUSH_OUTPUT command it is getting hanged in the previous byte transfer while loop or if we send directly STOP command,it is getting hanged in the I2C busy while loop (We checked the bus status using DPO,it is Free)
Thanks
Vijay