fingar wrote:
I forgot to tell you that you need to remove any drivers you have for this device from the kernel before using i2ctools, otherwise they are protected by the kernel and i2ctools can't get at them.
When I try something really simple (see code below) it doesn't work as I expected.
I've created 2 executables, one to test a write action, another to test a read action.
Running them through strace, everything appears normal but data never gets writtern (or read), I'll need to investigate that using a scope.
Code:
#include <stdio.h>
#include <linux/types.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/ioctl.h>
#include <linux/i2c.h>
#include <linux/i2c-dev.h>
#define TEST_WRITE 1
int main(int argc, char **argv)
{
int fd;
char buf[2];
fd = open("/dev/i2c-0", O_RDWR);
if (!fd)
{
perror("open(): ");
return 0;
}
ioctl(fd,I2C_SLAVE, 0x50); // set the eeprom address
ioctl(fd,I2C_TIMEOUT,10); // set the timeout
ioctl(fd,I2C_RETRIES,1); // set the retries
buf[0] = 0;
buf[1] = 0;
if (write(fd,&buf,2) != 2) // set address to read from/write to
perror("write()");
#ifdef TEST_WRITE
buf[0] = 0xAA;
buf[1] = 0x55;
if (write(fd, &buf, 2) != 2)
perror("write(): ");
#else
if (read(fd, buf, 2) != 2)
perror("read()");
printf("0: %02x\n", buf[0]);
printf("1: %02x\n", buf[1]);
#endif
close(fd);
return 0;
}