#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <errno.h>
#include <linux/i2c.h>
#include <linux/i2c-dev.h>
#include <unistd.h>

main()
{
	int file, i;
	char *filename = "/dev/i2c-0";
	struct i2c_rdwr_ioctl_data	msg_rdwr;
	struct i2c_msg			i2cmsg;
	char buf[17];

	if ((file = open(filename, O_RDWR)) < 0) {
 	   /* ERROR HANDLING: you can check errno to see what went wrong */
	    perror("Failed to open the i2c bus");
    		exit(1);
	}

	int addr = 0x50;          // The I2C address of the ADC
	if (ioctl(file, I2C_SLAVE, addr) < 0) {
	    printf("Failed to acquire bus access and/or talk to slave.\n");
	    /* ERROR HANDLING; you can check errno to see what went wrong */
	    	exit(1);
	}

	msg_rdwr.msgs = &i2cmsg;
	msg_rdwr.nmsgs = 1;

	i2cmsg.addr = 0;
	i2cmsg.flags = I2C_M_RD;
	i2cmsg.len = 17;
	i2cmsg.buf = buf;
	ioctl(file, I2C_RDWR, &msg_rdwr);

	for (i=0; i<16; i++)
		printf("%X ", buf[i]);
}
