#include <stdio.h>
#include <stdlib.h>
#include <linux/i2c-dev.h>
#include <fcntl.h>
void main()
{
int fd,i;
int addr = 0b10100000; // The I2C address of the ADC
char buf[10] = {0};
float data;
char channel;
if ((fd = open("/dev/i2c-4",O_RDWR | O_WRONLY | O_NDELAY )) < 0)
{
printf("Failed to open the bus.");
exit(1);
}
if (ioctl(fd,I2C_SLAVE,addr) < 0)
{
printf("Failed to acquire bus access and/or talk to slave.\n");
exit(1);
}
buf[0] = 0b00000000;
if (write(fd,buf,1) != 1)
{
printf("Failed to write to the i2c bus.\n");
printf("\n\n");
}
buf[0] = 0b00000000;
if (write(fd,buf,1) != 1)
{
printf("Failed to write to the i2c bus.\n");
printf("\n\n");
}
/* buf[0] = 0x00;
if (write(fd,buf,1) != 1)
{
printf("Failed to write to the i2c bus.\n");
printf("\n\n");
}
buf[0] = 0x00;
if (write(fd,buf,1) != 1)
{
printf("Failed to write to the i2c bus.\n");
printf("\n\n");
}
*/
buf[0] = 0b11111111;
if (write(fd,buf,1) != 1)
{
printf("Failed to write to the i2c bus.\n");
printf("\n\n");
}
if (read(fd,buf,1) != 1)
{
printf("Failed to read from the i2c bus.\n");
}
else
{
//data = (float)((buf[0] & 0b00001111)<<8)+buf[1];
//data = data/4096*5;
// channel = ((buf[0] & 0b00110000)>>4);
printf("value read=%c",buf[0]);
}
/*
for(i = 0; i<4; i++)
{
if (read(fd,buf,2) != 2)
{
printf("Failed to read from the i2c bus.\n");
}
else
{
data = (float)((buf[0] & 0b00001111)<<8)+buf[1];
data = data/4096*5;
// channel = ((buf[0] & 0b00110000)>>4);
// printf("Channel %02d Data: %04f\n",channel,data);
}
}
*/
}
This is my i2c program to write the data on to the EEPROM 24c64. but the address of eeprom is not detected by this and there is show the error as below
"Failed to acquire bus access and/or talk to slave."
So Please guide me to solved the problem.
Thnks In advanse.