With the above code
GolamMostafa:
If you are using UNO, then check that you have 2x10k pull-up connected to I2C Bus lines and A0/A1 pins of ADT7410 are shorted to GND. Re-run the following following program which includes few more lines to check that I2C bus transaction is OK.
#include <Wire.h>
byte a ;
void setup()
{
Serial.begin(9600);
Wire.begin();
//writing step
Wire.beginTransmission(0x48);//Slave I2C address
Wire.write(0x03);//position pointer to config reg address
Wire.write(0x80);//write config reg with 16bit mode
byte busStatus = Wire.endTransmission();
if (busStatus != 0x00)
{
Serial.println("I2C Transaction has failed...!");
while(1);
}
//reading back step
Wire.beginTransmission(0x48);//Slave I2C address
Wire.write(0x03);//position pointer to config reg address
Wire.endTransmission();
Wire.requestFrom(0x48, 1);//request 1 byte of data from slave
a = Wire.read();//assign value to a
//Wire.endTransmission();
Serial.print("Config=");
Serial.println(a, HEX);
}
void loop()
{
//delay(1000);
}
**BTW:**
**(1)** Before we were reading 0x00; now, you are reading 0x0C. Is it genuine or noise? Configuration bit has not changed; but, some other bits have changed which you have not requested.
**(2)** If the above codes do still fail, try to read the ID of the sensor; you should get a value: 0xC0 - 0xCF as per data sheet. Just change the address value from 0x03 (Config Reg) to 0x0B (ID Reg) and comment out un-needed lines.
I'm using an arduino Micro with 10K pull-up resistors. I2C is working since temperature can be read and vary with external heating when I use a library found online.
Using the code above return no printout to serial monitor, nothing. Modifying it to the code below returns the following:
New code:
#include <Wire.h>
byte a ;
byte busStatus;
void setup()
{
Wire.begin();
//writing step
Wire.beginTransmission(0x48);//Slave I2C address
Wire.write(0x03);//position pointer to config reg address
Wire.write(0x80);//write config reg with 16bit mode
busStatus = Wire.endTransmission();
//reading back step
Wire.beginTransmission(0x48);//Slave I2C address
Wire.write(0x03);//position pointer to config reg address
Wire.endTransmission();
Wire.requestFrom(0x48, 1);//request 1 byte of data from slave
a = Wire.read();//assign value to a
//Wire.endTransmission();
}
void loop()
{
if (busStatus != 0x00)
{
Serial.println("I2C Transaction has failed...!");
while(1);
}
else
{
Serial.println("I2C Transaction OK...!");
}
Serial.print("Config=");
Serial.println(a, HEX);
delay(1000);
}
New printout:
I2C Transaction OK...!
Config=C
As per your suggestion, reading the IC ID from 0x0B returns D, which is obviously not correct (outside range 0xC0 to 0cCF).
I have other IC's and after replacement, reg 0x03 now returns D. Changed reg address to 0x0b, 0x00 or 0x01 (adc address) and still returns D.
So there is definitely something fishy here, just not making sense. Monitored power lines and I2C bus with oscilloscope and no signs of noise.