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.

ADS1115: ADS1115 not responding for the address 0x48

Part Number: ADS1115

hello everybody,

I am interfacing ADS1115 with Nuvoton N76E003 using I2C.

I am using adc channel A0 and 5V suppy voltage.

I have connected ADDR pin of ADS1115 to GND.

When I am giving address 0x48 through master it gives 0x20 i.e.Master Transmit Address NACK as a reply.

so I am stuck here. Please find my attached code and suggest solution.

#define EEPROM_SLA 0x48
#define 	EEPROM_WR  0
#define     EEPROM_RD  1
#define SET_BIT3        0x08
#define SET_BIT4        0x10
#define P13_OpenDrain_Mode		P1M1|=SET_BIT3;P1M2|=SET_BIT3
#define P14_OpenDrain_Mode		P1M1|=SET_BIT4;P1M2|=SET_BIT4


#define I2C_ACK			0
#define I2C_NACK		1				 
#define timeout_count	1000
void INIT_I2C(void);
void ADS1115_config();
void ADS1115_read();
void I2C_start();
void I2C_stop();
void I2C_Master_Write(unsigned char value);
unsigned int I2C_Master_Read(unsigned short a);
void main()
{
	//MODIFY_HIRC_166();	
//---------------------I/O DEFINATION-----------------------------	
	
	//P1M1 = 0X80;	//FOR NORMAL PROGRAM

	
//----------------------FUNCTION CALLS----------------------------	
	
	INIT_I2C();
	I2C_start();
	ADS1115_config();
    ADS1115_read();
	 I2C_stop();
	while(1)
	{	     
    }
}

//----------------------------------I2C COMMUNICATION FOR DISPLAY--------------------------
void INIT_I2C(void)
{
	P13_OpenDrain_Mode;
	P14_OpenDrain_Mode ;
	SDA = 1;
	SCL = 1;
	I2CPX=0;  //SCL= P1.3 ,SDA=P1.4
	I2CEN=1;
	I2CLK=42;  //  400KBPS FOR 16MHZ CLOCK
}
//_________________________ADS1115 CONFIG AND DATA BLOCK_______________________//

void I2C_start(void)
{
	signed int t = timeout_count;
	
	STA = 1;                                
    SI = 0;
   
}

void I2C_stop(void)
{
	signed int t = timeout_count;
	
	SI = 0;
    STO = 1;    
}
void ADS1115_config()
{
 I2DAT = (EEPROM_SLA | EEPROM_WR);

 if(I2STAT == 0x18)
 {
 	LED = 1;
 }
 I2C_Master_Write(0x01);//Command to config registers    0x01
 I2C_Master_Write(0x80);//PGA: +-6.144V, Inputs: default (A0), continuous conv. mode		0x80
 I2C_Master_Write(0x83);//128 SPS, Traditional comparator, active low, nonlatching, dis. ALERT/RDY 	0x83
 
}
void I2C_Master_Write(unsigned char value)
{
 I2DAT = value; //Write data to SSPBUF
}
void ADS1115_read()
{
unsigned int datah;
unsigned int datal;

//float data;
I2C_Master_Write(0x90); 			//0x90
I2C_Master_Write(0x00); 			//0x00
I2C_Master_Write(0x91); 		   //0x91
datah = I2C_Master_Read(1);
datal = I2C_Master_Read(0);

}

unsigned int I2C_Master_Read(unsigned char ack_mode)
{
	signed int t = timeout_count;
	unsigned char value = 0x00;
	I2DAT = (EEPROM_SLA | EEPROM_RD);
	t = timeout_count;
	AA = 1;                             
    SI = 0;
    while((SI==0)&&(t>0)) 
	{
		t--;
	};   	
	
	value = I2DAT;

	if(ack_mode == I2C_NACK)
	{
		t = timeout_count;
		AA = 0;   
		SI = 0;
		while((SI == 0)&& (t>0)) 
		{
			t--;
		};   		
	}
	
	return value;

}

  • Hello,

    Can you please share a capture of the I2C communication waveforms using an oscilloscope?  Our ADS111x experts will get back with you early next week.

  • Gandhali,


    I would agree with Collin that you should use a logic analyzer or oscilloscope to look at the communication between the device and the microcontroller. Note that the communication should look exactly like the communication shown in figures 30 and 31 in the datasheet.

    Also, the registers in this device, including the config and conversion registers, are both 16 bits and are sent sequentially, while it looks like you are using 8 bit transactions for your write. Again, use the logic analyzer or oscilloscope to look at the I2C communication.


    Joseph Wu

  • Gandhali,


    A colleague just noticed that you've contructed the address read/write incorrectly. The I2C address is 48h, but that is the upper 7 bits of the write. In your address, you use 48h as the byte and then and OR it with 0 or 1 for a write or a read. For the I2C address, you should 90h and then OR it with 0 or the 1 for the write or read. From the timing diagram, you can see it here:




    Joseph Wu

  • hello Joseph,

    Thank you for your suggestion.

    I have written slave id 0x90 as per your suggestion but still its not responding.

  • Gandhali

    In that case, I think we need to see the SDA and SCL signals from an oscilloscope or logic analyzer. It is the best way to determine what the microcontroller is sending out and what the device is responding to.

    Get a scope shot and post it back here. Make sure there's enough detail to see the individual bits in the address and data.

    Joseph Wu

  • Gandhali,

    I haven't heard from you in a while, so I thought I'd check to see if you've solved your communication problem. In my last post, I suggested that you look at the communication with a scope or logic analyzer, and I think that's the best way to help debug these problems.

    I'll close this post for now, but if you are continuing to have problems, please post back and we can work on this again.

    Joseph Wu

  • hello sir,

    Actually I don't have logic analyzer and I am unable to capture images of waveforms on CRO.

    The problem is still there.

  • Gandhali,

    I think its very important to get a look at a scope shot of the ADC communications. Without this, it's impossible to know if the microprocessor is even sending out communication or commands to anything. Without this view, it's extremely difficult to debug these kind of problems.

    Joseph Wu

  • Hello Joseph,

    We have Tektronix TBS 1072B 70MHz digital oscilloscope and its difficult to capture shot on it.

    So should we run the program in a loop and then take a shot on it??

  • Gandhali,


    It should be fine to use that scope. Just use the scope to monitor the SDA and SCL lines on the ADS1115. Have it trigger on the first falling edge of the SCL line and see the following bytes come out.

    Make sure that you are able to read the bits directly. I would want to see enough detail to be able to read byte transactions completely.


    Joseph Wu

  • Hello Joseph,

    I have attached my screenshot in which Yellow waveform shows SCL and Blue waveform shows SDA line. Right now I am getting 0x18 in I2STAT register of N76E003 which suggests that START condition and ADDRESS of slave i.e. ADS115 is correct according to datasheet of N76E003.

    Now when I send DATA there should be 0x28 in I2STAT register of N76E003, but it is not replying the same.

    So is there any problem in sending data or can you suggest me commands for data as per specification mentioned in above threads.

  • Gandhali,


    I'm sorry, but I thought I had responded to this on Friday, but I must have lost it in my browser's response.

    First, I was hoping to see a bit more of the transaction. The write to and read from the device take 4 or 5 bytes and I can basically see 1 byte and parts of two more, so I don't know what the transaction is doing. I would note that the device does ACK the 9th bit so the device is responding to the I2C bus.

    In your I2C transactions, are you continuously writing to and reading from the device? I would space out communication so there is some delay between starting a conversion and reading back data from the device. Exactly what order are you sending commands. Normally, I would expect something like this:

      Configure device/Start conversion - single-shot conversion mode
      Wait for conversion to complete
      Read Conversion
      Repeat for new configuration

    For the wait for conversion to complete, the time is based on the data rate. Because the device has an internal oscillator and that oscillator has some variation. To complete the conversion you need to add 10% for variation and 20us to start up the device for conversion. For 128SPS, the data period is 7.82ms. Adding 10% and 20us for the wait time would be a period of 8.62ms.



    Joseph Wu

  • Hello Joseph,

    Sorry Joseph I am replying late due to Diwali vacation.

    In my I2C communication now I am able to write data but I am unable to read ADC conversion result.

    what would be the possible reasons??

  • Hello Joseph,

    I am uploading my updated code and now I am able to catch waveform on logic analyzer but still I am not getting ADC value through ADC.

    I have connected my input between AIN0 and GND.

    So please go through my code as well as shot from logic analyzer and suggest some solution.

    #include <intrins.h>		 
    #include <n76_FINAL.h>
    #define EEPROM_SLA 0x90
    #define 	EEPROM_WR  0
    #define     EEPROM_RD  1
    #define SET_BIT3        0x08
    #define SET_BIT4        0x10
    #define P13_OpenDrain_Mode		P1M1|=SET_BIT3;P1M2|=SET_BIT3
    #define P14_OpenDrain_Mode		P1M1|=SET_BIT4;P1M2|=SET_BIT4
    
    unsigned int adval;
    unsigned int adval1;
    
    #define I2C_ACK			0
    #define I2C_NACK		1				 
    #define timeout_count	1000
    void INIT_I2C(void);
    void ADS_config();
    void ADS_read();
    void I2C_start();
    void I2C_stop();
    void I2C_Master_Write(unsigned char value);
    unsigned int I2C_Master_Read(unsigned short a);
    void I2C_Master_Wait();
    void delay(unsigned int t);
    void main()
    {
    	
    	INIT_I2C();
    //	I2C_start();
    	ADS_config();
        
    	while(1)
    	{
    	 
    	 _nop_();
    	 _nop_();
    	 _nop_();
    	 _nop_();
    	 _nop_();
    	 _nop_();
    	 _nop_();
    	 _nop_();
    	 _nop_();
    	 _nop_();
     	 _nop_();
     	 _nop_();
    	 
    	 
    //	delay(10);
    	 ADS_read();
    	// I2C_stop();
    //	delay(10);
        }
    }
    
    //----------------------------------I2C COMMUNICATION FOR DISPLAY--------------------------
    void INIT_I2C(void)
    {
    	P13_OpenDrain_Mode;
    	P14_OpenDrain_Mode ;
    	SDA = 1;
    	SCL = 1;
    	I2CPX=0;  //SCL= P1.3 ,SDA=P1.4
    	I2CEN=1;
    	I2CLK=39;  //  400KBPS FOR 16MHZ CLOCK
    }
    //_________________________ADS1115 CONFIG AND DATA BLOCK_______________________//
    
    void I2C_start(void)
    {
    	signed int t = timeout_count;
    	 
    	STA = 1; 
    	SI = 0;
    	//delay(10);
    	
    	_nop_();
     	_nop_();
     	_nop_();
    	 
    	STA=0;
    	   
    }
    
    void I2C_stop(void)
    {
    	signed int t = timeout_count;
    	
    	SI = 0;
        STO = 1;    
    }
    void ADS_config()
    {
    	 EA=0;
     	I2C_start();
    	I2C_Master_Wait();
     	I2DAT = EEPROM_SLA;
     	I2C_Master_Wait();
     	if(I2STAT == 0x18)
     	{
     		LED = 1;
     	}
    	STA=0;	    //added and it works
    //	delay(10);
    
    _nop_()	  ;
    _nop_()	  ;
    _nop_()	  ;
    _nop_()	  ;
    _nop_()	  ;
    I2DAT = 0x01 ;	  //Command to config registers pointing to config reg ykr   0x01
    I2C_Master_Wait();	 
    //I2C_Master_Write(0x01);//Command to config registers pointing to config reg ykr   0x01
    _nop_()	  ;
    _nop_()	  ;
    _nop_()	  ;
    _nop_()	  ;
    _nop_()	  ;
    //I2C_Master_Wait();
    I2DAT = 0xC4 ;	 //PGA: _2.048v, Inputs:  AIN0 & GND , continuous conv. mode		0xC4
    I2C_Master_Wait();	 
    _nop_()	  ;
    _nop_()	  ;
    _nop_()	  ;
    _nop_()	  ;
    _nop_()	  ;
    I2DAT = 0xE0 ;//860 SPS, Traditional comparator, active low, nonlatching, assert after one conv.	0xE0
    I2C_Master_Wait();
    _nop_()	  ;
    _nop_()	  ;
    _nop_()	  ;
    _nop_()	  ;
    _nop_()	  ; 
     //I2C_stop();
     
    }
    void I2C_Master_Write(unsigned char value)
    {
     I2DAT = value; //Write data to SSPBUF
     if(I2STAT == 0x28)
     {
     	LED = 1;
     }
    }
    void ADS_read()
    {
      I2C_start();
      I2C_Master_Wait();
     	I2DAT = EEPROM_SLA;	 //90 
     	I2C_Master_Wait();
    	I2C_start(); 
    
    	 I2DAT = 0x00 ;		 // ADDRESS POINTER
    I2C_Master_Wait();
    
     
    
     I2DAT = EEPROM_SLA | EEPROM_RD ;  //0X91
     I2C_Master_Wait();
     //delay(100);
     I2DAT = 0x00 ;		 // ADDRESS POINTER
    I2C_Master_Wait();
     
     
    I2DAT = 0x01 ;		 // ADDRESS POINTER
    I2C_Master_Wait();
    
    
    STA=0;
    STO=0;
    SI=0;
    AA=1;
    
    I2C_Master_Wait();
    adval=I2DAT	 ;
    
    I2C_Master_Wait();
    adval1=I2DAT  ;
    
    }
    void I2C_Master_Wait()
    {
       SI=0;
       while (!SI);
      {	  
      } //Transmit is in progress
    }
    
    //********************************************************
     void delay(unsigned long t)
    {
    	unsigned long i,j;
    	for(j=0;j<t;j++)
    		for(i=0;i<7500;i++);
    }
    

  • Gandhali



    Thanks for the logic analyzer photos, I think they could help a lot. Because I also have a Saleae analyzer, can you save the .logicdata file? You should be able to post it back here if it's not too large.

    Looking at the I2C exchange, I think you've set up the read wrong. It starts with a 90 write, then a 00 for the conversion register pointer, then 91 for the read for the last two bytes.



    Joseph Wu

  • Joseph,

    We have observed waveform on logic analyzer using code in arduino.

    There was problem in my START and STOP condition.

    So my issue is resolved.

    Thank you for your support.