Advertisement
Guest User

Untitled

a guest
Sep 23rd, 2017
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.98 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <fcntl.h>
  3. #include <stdlib.h>
  4. #include "/usr/include/linux/i2c-dev.h"
  5.  
  6. int main(void)
  7. {
  8.         int fd;
  9.         char filename[20];
  10.         char buf[10],batt;
  11.         int res;
  12.         batt=0;
  13.  
  14.         sprintf(filename, "/dev/i2c-0");
  15.         fd = open(filename, O_RDWR);
  16.         if (fd < 0) {
  17.                 printf("Error on open\n");
  18.                 exit(1);
  19.         }
  20.  
  21.         if (ioctl(fd, I2C_SLAVE, 0x05) < 0) {
  22.                 printf("Error on slave address\n");
  23.                 exit(1);
  24.         }
  25.  
  26.  
  27.         buf[0] = 0x01;
  28.         buf[1] = 0x3F;
  29.         if(write(fd,buf,2)!=2)
  30.         {
  31.                 printf("Para nicht uebergeben\n");
  32.         }
  33.  
  34.  
  35.         buf[0] = 0x00;
  36.         buf[1] = 0x03;
  37.         if(write(fd,buf,2)!=2)
  38.         {
  39.                 printf("Befehl nicht geschrieben\n");
  40.         }
  41.  
  42.  
  43.         batt = 0x15;
  44.         read(fd,batt,1);
  45.  
  46.  
  47.  
  48.         printf("Alles OK\n\n");
  49.         close(fd);
  50.  
  51.         return 0;
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement