4 set the output voltage from the D/A
5 -----------------------------------
7 1) send the i2c address
11 usage :- type with spaces but without the < >
12 <AD5602_test1> <address as decimal> <HI_byte> <LO_byte>
18 #include <sys/ioctl.h>
19 #include <linux/i2c.h>
21 int main(int argc, char** argv)
24 int HI_byte; /* last 4 bits are output byte HI bits */
25 int LO_byte; /* first 4 bits are output byte LO bits */
26 int buf[1]; /* use to feed the i2c driver */
27 int address; /* i2c bus address */
29 if (argc != 4) /* report error if we are not getting just 3 inputs after the program name */
31 printf("Error. usage (decimal): %s AD5602_test1 address HI_byte LO_byte\n", argv[0]);
34 address = atoi(argv[1]); /* address is the first number after the program name */
35 // address bits are 0 0 0 1 1 1 0 R/W as per manual
36 // the 1 0 before R/W is for the address pin (pin 1) open-circuit
37 // the R/W is 0 for write. Linux see the chip address as 0000 1110 (0E) - shifts a bit to the left - odd!
38 HI_byte = atoi(argv[2]); /* HI_byte is 0 0 0 0 D7 D6 D5 D4 */
39 LO_byte = atoi(argv[3]); /* LO_byte is D3 D2 D1 D0 X X X X (X = anything) */
41 i2c = open("/dev/i2c/0",O_RDWR); /* open the i2c-bus number 0 */
43 ioctl(i2c,I2C_SLAVE,address); /* set the i2c-bus address of the chip we will talk to */
45 buf[0] = HI_byte; /* HI_byte */
46 buf[1] = LO_byte; /* LO_byte */
49 write(i2c,buf,2); /* we send 2 bytes <HI_byte> <LO_byte> */
51 printf("%d\n", buf[0]); /* just to prove it ran!*/
52 printf("%d\n", buf[1]);
57 // AD5602_test1 14 0 0 gives 0 volts
58 // AD5602_test1 14 8 0 gives 2.5 volts 8 = 08 00001000 0 = 00 00000000
59 // AD5602_test1 14 15 240 gives 5 volts 15 = 0F 00001111 240 = F0 11110000