hi,
i connect ads1115 by twi interface,just look my source code:
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <fcntl.h>
#include <string.h>
#include <linux/i2c-dev.h>
#define BYTE unsigned char
int main()
{
printf("****************************************\n");
//open device file
int file;
int adapter_nr=1;
char filename[20];
snprintf(filename,19,"/dev/i2c-%d",adapter_nr);
file=open(filename,O_RDWR);
if(file<0)
{
printf("open device file failed !\n");
exit(-1);
}
printf("int file=%d\n",file);
//specify device address
int addr=0x48;
int ioctlnum=-1;
ioctlnum=ioctl(file,0x0703,addr);
if(ioctlnum<0)
{
printf("specify device address failed !\n");
exit(-1);
}
printf("int ioctlnum=%d\n",ioctlnum);
printf("\n\n");
BYTE wbyte[4];
wbyte[0]=0x90;
wbyte[1]=0x01;
wbyte[2]=0xff;
wbyte[3]=0xff;
int i=0;
for(i=0;i<4;i++)
{
if(write(file,&wbyte[1],1)!=1)
{
printf("write %d byte error\n",i);
}
}
for(i=0;i<200;i++)
printf("*");
printf("\n");
BYTE rbyte[5];
rbyte[0]=0x90;
rbyte[1]=0x01;//choose a register to read
rbyte[2]=0x91;
rbyte[3]='\0';
rbyte[4]='\0';
for(i=0;i<3;i++)
{
if(write(file,&rbyte[i],1)!=1)
{
printf("read %d byte error\n",i);
}
}
read(file,&rbyte[3],1);
read(file,&rbyte[4],1);
printf("read data = 0x%02x%02x\n",rbyte[3],rbyte[4]);
}
and i run it in my board myd-sama5d36-c , no matter what register i want to read ,such as config register, conversion register and so on, the result is 0x8585.
so ,what's wrong with my code ?
Sincerely !