This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

question about ads1115 under linux3.6.9 , always return 0x8585.

Other Parts Discussed in Thread: ADS1115

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 !

  • Hello,

    Thank you for your inquiry. We will respond to this query shortly.

    Regards,

    Krunal

  • user4777031,


    I'm not sure what your problem is. We don't provide much help when it comes to debugging someone's code. We are able to help more when there are questions about the device itself.

    Looking at the read result, 8585h is a slightly unusual value. Normally when you read the configuration register, the result is 8583h. I'm guessing that you have made a mistake in the code such that you are reading the configuration register over and over.

    There are two things that I would try. First, write a different value to the configuration register that is completely different than the default and read it back, change the PGA, and data rate completely to make sure the communication is corret. Second, I would get a logic analyzer or oscilloscope to make sure that the communication is correct. Verify that any read is really reading 8585h each time and that you aren't reading the data and losing it in the reporting of the value.


    Joseph Wu