//gcc -o lm75_test lm75_test.c // #include #include #include #include #include #include #include int main(int argc, char **argv) { int rtc; char *i2cFileName = "/dev/i2c-3"; // char *i2cFileName = "/sys/class/i2c-dev/i2c-3"; int rtcAddress = 0x90 >> 1; unsigned char buf[16]; printf("***** start i2c test program *****\n"); printf("Initializing RTC unit... Please wait\n"); usleep(5000); if ((rtc = open(i2cFileName, O_RDWR)) < 0) { printf("Faild to open i2c port\n"); exit(1); } if (ioctl(rtc, I2C_SLAVE, rtcAddress) < 0) { printf("Unable to get bus access to talk to slave\n"); exit(1); } buf[0] = 0; if ((write(rtc, buf, 1)) != 1) { printf("Error writing to i2c slave\n"); exit(1); } if (read(rtc, buf, 2) != 2) { printf("Uneble to read\n"); exit(1); } printf("%x\n", buf[0]); printf("%x\n", buf[1] & 0x80); return 0; }