Guest User

Untitled

a guest
Apr 26th, 2018
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.05 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <errno.h>
  4. #include <linux/i2c-dev.h>
  5. #include <linux/i2c.h>
  6. #include <stdlib.h>
  7. #include <stdio.h>
  8. #include <unistd.h>
  9. #include <memory.h>
  10. #include <fcntl.h>
  11. #include <errno.h>
  12. #include <sys/io.h>
  13. #include <sys/ioctl.h>
  14.  
  15. int main() {
  16. cout << "!!!Hello World!!!" << endl; // prints !!!Hello World!!!
  17.  
  18. int Address = 0x39; //Slave addr
  19.  
  20. char i2c_dev_node_path[] = "/dev/i2c-0";
  21.  
  22. int ret_val = 0;
  23. /* Open the device node for the I2C adapter of bus 0 */
  24. i2c_dev_node = open(i2c_dev_node_path, O_RDWR);
  25. if (i2c_dev_node < 0)
  26. {
  27. cout << "EROR Unable to open device node." << endl;
  28. return -1;
  29. }
  30.  
  31.  
  32. int i2c_dev_address = 0x39;
  33.  
  34. ret_val = ioctl(i2c_dev_node,I2C_SLAVE,i2c_dev_address);
  35. if (ret_val < 0)
  36. {
  37. perror("Could not set I2C_SLAVE.");
  38. cout << "EROR Could not set I2C_SLAVE." << endl;
  39. return -1;
  40. }
  41.  
  42. cout << "ALL OK!!!!!" << endl;
  43.  
  44.  
  45. int retVal = i2c_smbus_read_word_data ( i2c_dev_node , 0xac );
  46.  
  47. }
Add Comment
Please, Sign In to add comment