2-Wire Serial Temperature Sensor

LesJones

Joined Jan 8, 2017
4,174
With I2C protocol there are two types of addresses. The slave address (Which is the one you are asking about.) is the address of the device on the bus. As the full slave address is 7 bits there can be up to 128 devices (In theory) on the bus. The top 4 bits for this device are fixed at 1001 (Binary.) 0x9 (Hex) The lower 3 bits (A0 to A2) you can set by connecting these pins to ground (for zero) or VDD (For a one.) This means that you can have a maximum of 8 of this device type on the bus. When communicating with the device the first thing you send after the start condition is the slave address followed by the read/write bit. The device then responds with an acknowledge. (But only if the address is it's address) See page 12 of the data sheet for more details of the protocol. (I find I have to refresh my memory when writing code for an I2C device I have not used before.) The other type of address is the register address. That selects the register within the device that you want to read or write to. Think of the slave address like your house address and the register address as the name of the person in your house. I can give you examples of code that runs on a PIC12F1840 to read data from an INA219 (Current and voltage sensor.) or a BMP280 (Temperature and pressure sensor.) if that will be any use to you.

Les.
 
Last edited:

Thread Starter

aspirea5745

Joined Apr 17, 2019
99
See page 12 of the data sheet for more details of the protocol. (I find I have to refresh my memory when writing code for an I2C device I have not used before.) The other type of address is the register address. That selects the register within the device that you want to read or write to.
Les.
@LesJones Thanks for detailed answers

Slave address will 10011110 ( if A0 to A2 connected to VDD) to Write data
Slave address will 10011111 (if A0 to A2 connected to VDD) to Read data

The other type of address is the register address. That selects the register within the device that you want to read or write to
Datasheet say there are five register table 5.7 on the page 11 and 12 of datasheet

Which is the second byte after sending slave address ? Which register need to select to measure temperature ?
 

LesJones

Joined Jan 8, 2017
4,174
The next thing after sending the slave address (And receiving an ACK.) is to send the register address. (I have subroutines for all the basic I2C functions in my code.) To read the temperature value you need to do two I2C reads as the temperature value is 16 bits. After a quick look though the data sheet I could not find a table of register addresses. The first time I had to write code to work with I2C protocol it took me some time to fully understand the protocol. If you are clever enough to write in "C" there will be pre written I2C drivers. "C" is too difficult for me so I use assembler.

Les.
 

Papabravo

Joined Feb 24, 2006
21,159
After a quick look though the data sheet I could not find a register address in the datasheet . Where is register address given in the datasheet ?
It is in Table 5-1 on page 10
It is a 2-step process
  1. Write the pointer register which is WRITE ONLY (A 2-byte transaction)
  2. Read the Register, pointed at by the Pointer Register (A 3 byte transaction)
 

Thread Starter

aspirea5745

Joined Apr 17, 2019
99
It is in Table 5-1 on page 10
It is a 2-step process
  1. Write the pointer register which is WRITE ONLY (A 2-byte transaction)
  2. Read the Register, pointed at by the Pointer Register (A 3 byte transaction)
alright, there are total four register address in device

1586579809793.png

Condition : Write data to TEMP register

1586580804582.png

I do not understand when to use the rest of the registers and in which sequence to use them?
 
Last edited:

LesJones

Joined Jan 8, 2017
4,174
If you are only interested tin READING the temperature you only need to read the temperature register. Writing to the configuration register modifies the way the device behaves. You need to READ the data sheet fully to understand what the different configurations do. I think they are related to the function of the INT pin on the device but I have only skimmed through the data sheet. I have not spent enough time reading and understanding it. The Tset register is the set point temperature when using the device as a thermostat. The Tyust register sets the amount of hysteresis in the thermostat function.
I think we have all been confused by the use of the term POINT register which seems to be being used meaning the device register address.

Les
 

Thread Starter

aspirea5745

Joined Apr 17, 2019
99
You need to READ the data sheet fully to understand
I was looking at the datasheet, then some questions came to my mind

If you are only interested tin READING the temperature you only need to read the temperature register.
We can read data from a device only when the data will be stored in device. We can read data from the temperature register only when the data is stored in the temperature register

We can write data to a device through I2C. We can read data from a device through I2C.

Do you mean that I do not need to send the data to device if I just want to read temperature. I just need to send address of temperature register to read temperature value ?

I think we have all been confused by the use of the term POINT register which seems to be being used meaning the device register address.
I am agree with you
 

LesJones

Joined Jan 8, 2017
4,174
If the point register bits 0 & 1 default to zero at power on then I don't think you need to any of the registers before reading the temperature register. (You still need to do an I2C write to put the slave address on the bus.) I would start by writing small bits of code to make sure the device behaves the way you think it does. One think I would confirm is that the point register remains set to the last value it was set to. (Rather than returning to zero after a read or write transaction.) This is easy to do in assembler but I have no idea how you would do this in "C". (.h files in "C" seem to do most of the work in "C" program. they just seem like black magic to me which is why I find "C" so difficult.)

Les
 

Thread Starter

aspirea5745

Joined Apr 17, 2019
99
If the point register bits 0 & 1 default to zero at power on then I don't think you need to any of the registers before reading the temperature register. (You still need to do an I2C write to put the slave address on the bus.) I would start by writing small bits of code to make sure the device behaves the way you think it does. One think I would confirm is that the point register remains set to the last value it was set to. (Rather than returning to zero after a read or write transaction.) This is easy to do in assembler but I have no idea how you would do this in "C". (.h files in "C" seem to do most of the work in "C" program. they just seem like black magic to me which is why I find "C" so difficult.)

Les
I am trying to understand complete byte sequence of i2c protocol for sensor. I gone through the datasheet. I can understand address byte and pointer byte butBut I do not understand which register address should be selected

I found in Google search that after sending address of slave, we send address of config register But I did not understand the reason why we select the config register. Do you know why this happens?
 

LesJones

Joined Jan 8, 2017
4,174
The configuration register controls the way the device behaves. So you first need to set it to behave the way you want. You should only need to do this once at the start of your code when it has first been powered on. The best explanation I have seen on I2C protocol is in the BMP280 data sheet which I have attached. The I2C part of the data sheet is a very small part of the data sheet but I found it made me understand I2C protocol better than web tutorials and other data sheets.

Les.
 

Attachments

Thread Starter

aspirea5745

Joined Apr 17, 2019
99
The configuration register controls the way the device behaves. So you first need to set it to behave the way you want. You should only need to do this once at the start of your code when it has first been powered on. The best explanation I have seen on I2C protocol is in the BMP280 data sheet which I have attached. The I2C part of the data sheet is a very small part of the data sheet but I found it made me understand I2C protocol better than web tutorials and other data sheets.

Les.
I have looked datasheet, Connecting SDO to GND results in slaveaddres is 01110110(0x76), after sending slave address 0x76, next we send register address, which register address do you select for temperature?
 
Top