Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <fcntl.h>
- #include <stdlib.h>
- #include "/usr/include/linux/i2c-dev.h"
- int main(void)
- {
- int fd;
- char filename[20];
- char buf[10],batt;
- int res;
- batt=0;
- sprintf(filename, "/dev/i2c-0");
- fd = open(filename, O_RDWR);
- if (fd < 0) {
- printf("Error on open\n");
- exit(1);
- }
- if (ioctl(fd, I2C_SLAVE, 0x05) < 0) {
- printf("Error on slave address\n");
- exit(1);
- }
- buf[0] = 0x01;
- buf[1] = 0x3F;
- if(write(fd,buf,2)!=2)
- {
- printf("Para nicht uebergeben\n");
- }
- buf[0] = 0x00;
- buf[1] = 0x03;
- if(write(fd,buf,2)!=2)
- {
- printf("Befehl nicht geschrieben\n");
- }
- batt = 0x15;
- read(fd,batt,1);
- printf("Alles OK\n\n");
- close(fd);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement