I2C Telemetry - Reading out a register to serial monitor

Hi,

I am currently trying to write a sketch to use an Uno to read the die temperature of a switching regulator with 16bit telemetry. It is a chip from linear technology that I have designed and built a circuit around.

Here is the data sheet LTC4162-L Datasheet and Product Info | Analog Devices

I think I can see on my oscilloscope that the slave is writing back (the packet gets much shorter when SDA or SCL are disconnected from the slave).
The bypassing etc looks ok, I don’ think the ripple on Dvv (slightly visible on SDA when SCL transitions but
SDA does not) is causing unwanted transition or putting voltages in the undefined region or anything like that. I think the hardware is fine.

My first question is about the storage of the variable being read. I am sure this is pretty basic of a thing not to know but I don’t know what data type I should be using and how many bytes I should be requesting (or should I be using the method I have seen that uses ‘while’ to allow for less bytes to be sent?
As you can see in the code I have set it up to print the variable directly as it is stored to the serial monitor before attempting any processing so I can work on getting that right first.

As I said it’s 16bit telemetry and the register in question ‘die_temp’ has the address ‘0x3F’ a bit range of ‘[15:0]’, a default of ‘0’ and ‘R’ Access.

My second question is have I used anything like the right operators to implement the calculation shown in the data sheet for converting the value in the register to degrees centigrade?

"Signed number that indicates the A/D measurement for the die temperature. The value
can be calculated from the A/D reading in °C as TDIE(°C) = die_temp × 0.0215°C/LSB

  • 264.4°C.
    thermistor_voltage 0x40 R [15:0] 0 Signed number"

Here is the code

#include <Wire.h>

void setup() {
  Wire.begin();
  Serial.begin(9600);
}

void loop(){
  
  Wire.beginTransmission(0b1101000);             //Send the start bit with the write bit set and then 
                                                                        send the address of the slave
  Wire.write(0X3F);                                         //Set the pointer to the register holding the Die 
                                                                      Temperature
  Wire.endTransmission();                               //End transmission so the pointer is not moved with the 
                                                                       next write???(I can see on my scope that the slave is 
                                                                       not writng back with out this)

  Wire.requestFrom(2, 0b1101000);                      //Restart the transmission with the read bit set and then request 2 bytes from the slave
  long DieRegister = Wire.read();                          //Store the variable (I think this is what I am 
                                                                            Struggling with)
  Serial.print ("Die_register = ");                          //Label the value to be printed
  Serial.println (DieRegister);                                            //Print the variable I have stored before 
                                                                                     mathmatical 
                                                                                     processing to try to see what's not working
  int  DieTemp = DieRegister * 0.0215 / bit(16)- 264.4;     //Trying to implement the calculation the data 
                                                                                     sheet recommends - "The value
                                                                                     can be calculated from the A/D reading in °C 
                                                                                      as 
                                                                                     TDIE(°C) = die_temp × 0.0215°C/LSB - 
                                                                                     264.4°C."
  Serial.print ("Die_Temperature = ");                               //Label the value to be printed
  Serial.print (DieTemp);                                                  //Print the calculated Temperature value
  Serial.println ("°C");                                                      //Give the unit

    delay(500);
}

I really been trying to get to grips with the basics of bit maths etc to get this running over the last few days but I am just stabbing in the dark and getting nonsense values back.

TIA

I2C Bus is a byte oriented serial data communication protocol; where, data exchange happens one byte at a time; accordingly, I have brought some modifications in your sketch; the modified/adjusted sketch is given below: (At what page of data sheets have you got the device address as 1101000?)

#include <Wire.h>
#define slaveAddress 0b1101000   //always 7-bit
void setup()
{
  Wire.begin();
  Serial.begin(9600);
}

void loop()
{
  Wire.beginTransmission(slaveAddress); //(0b1101000); Write mode is automatic
  Wire.write(0X3F);   //Set the pointer to the register holding the Die Temperature
  Wire.endTransmission();  //End transmission so the pointer is not moved with the

  Wire.requestFrom(slaveAddress, 2);//request 2 bytes from the slave
  byte DieRegisterLByte = Wire.read(); //Store the variable //which byte first? check data sheets
  byte DieRegisterHByte = Wire.read(); //read/store high byte
  int DieRegister = DieRegisterHByte << 8 | DieRegisterLByte;
  Serial.print ("Die_register = "); //Label the value to be printed
  Serial.println (DieRegister);  //Print the variable I have stored before
  float  DieTemp = DieRegister * 0.0215 - 264.4;
  //TDIE(°C) = die_temp × 0.0215°C/LSB -264.4°C."
  Serial.print ("Die_Temperature = ");    //Label the value to be printed
  Serial.print (DieTemp, 2);  //2-digit after decimal point  
  Serial.println ("°C");    //Give the unit
  delay(1000);
}

Thanks for the reply.

I found the address a few rows down the table on page 6.

Is page 14 where I should know which byte to read first? I can't find it mentioned elsewhere but I don't understand it.

I will try your code tomorrow. Can I just try reading each byte first and look for room temperature?

Thanks again.

Can I just try reading each byte first and look for room temperature?

No, you have to read the values into a 16 bit signed integer variable, and use the formula you quoted. That requires a 2-byte I2C read operation.

As page 14 of the data sheet makes clear, the first byte read is the low byte of the signed value.

Hi, thanks for the help. I will look again at page 14 and try to understand for myself that and more i2c stuff in general.

It worked and read out correct data. The longer term goal was to read out more data and find out why it wasn't starting up and switching but something failed in the chip and it has now become an expensive silicone resistor/heater but I will assemble another one.

Thanks!