Advantech RSB-4210 Evaluation Kit User Manual Page 66

  • Download
  • Add to my manuals
  • Print
  • Page
    / 104
  • Table of contents
  • BOOKMARKS
  • Rated. / 5. Based on customer reviews
Page view 65
RSB-4210 User Manual 58
somewhat dynamically, so you cannot assume much about them. They can even
change from one boot to the next.
Next thing, open the device file, as follows:
int file;
int adapter_nr = 2; /* probably dynamically determined */
char filename[20];
snprintf(filename, 19, "/dev/i2c-%d", adapter_nr);
file = open(filename, O_RDWR);
if (file < 0) {
/* ERROR HANDLING; you can check errno to see what went
wrong */
exit(1);
}
When you have opened the device, you must specify with what device address you
want to communicate:
int addr = 0x40; /* The I2C address */
if (ioctl(file, I2C_SLAVE, addr) < 0) {
/* ERROR HANDLING; you can check errno to see what went
wrong */
exit(1);
}
Well, you are all set up now. You can now use SMBus commands or plain I2C to
communicate with your device. SMBus commands are preferred if the device sup-
ports them. Both are illustrated below.
__u8 register = 0x10; /* Device register to access */
__s32 res;
char buf[10];
/* Using SMBus commands */
res = i2c_smbus_read_word_data(file, register);
if (res < 0) {
/* ERROR HANDLING: i2c transaction failed */
} else {
/* res contains the read word */
}
/* Using I2C Write, equivalent of
i2c_smbus_write_word_data(file, register, 0x6543) */
Page view 65
1 2 ... 61 62 63 64 65 66 67 68 69 70 71 ... 103 104

Comments to this Manuals

No comments