Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <string.h>
- #include <errno.h>
- #include <linux/i2c-dev.h>
- #include <linux/i2c.h>
- #include <stdlib.h>
- #include <stdio.h>
- #include <unistd.h>
- #include <memory.h>
- #include <fcntl.h>
- #include <errno.h>
- #include <sys/io.h>
- #include <sys/ioctl.h>
- int main() {
- cout << "!!!Hello World!!!" << endl; // prints !!!Hello World!!!
- int Address = 0x39; //Slave addr
- char i2c_dev_node_path[] = "/dev/i2c-0";
- int ret_val = 0;
- /* Open the device node for the I2C adapter of bus 0 */
- i2c_dev_node = open(i2c_dev_node_path, O_RDWR);
- if (i2c_dev_node < 0)
- {
- cout << "EROR Unable to open device node." << endl;
- return -1;
- }
- int i2c_dev_address = 0x39;
- ret_val = ioctl(i2c_dev_node,I2C_SLAVE,i2c_dev_address);
- if (ret_val < 0)
- {
- perror("Could not set I2C_SLAVE.");
- cout << "EROR Could not set I2C_SLAVE." << endl;
- return -1;
- }
- cout << "ALL OK!!!!!" << endl;
- int retVal = i2c_smbus_read_word_data ( i2c_dev_node , 0xac );
- }
Add Comment
Please, Sign In to add comment