How to use the TCN75 temperature sensor
In this article I'm going to show to you how to use the TCN75 we have mounted on our boards.
- Temperature sensor and real time clock for Arduino
- A PIC 12f1840 developer board with mcp79410 RTC and tcn75 temperature sensor.
The TCN75 is a very simple temperature sensor but at the same time it is very accurate, with a precision of ±0,5 ° C, fra 25°C≤ TA ≤ 100°C e ±3 °C -55°C≤ TA ≤ +125°C.
The TCN75 needs only 0,25mA when it is in operative mode and 1uA when acting in stand-by mode.
The TCN75 communicates over an I2C™ bus and provides three programmable address pins, they can be programmed using hardware jumpers allowing up to 7 devices on the same bus.
It has a programmable pin used to signal if the temperature overcomes a defined value(user programmed set point). The TCN75 comes with a default value for the set point at 80 °C with 5 °C for the hysteresis.
The most important characteristics for this sensor are the ones shown in the following table:
Solid state sensor for temperature measurement | ||
accuracy | 0.5 °C | [25°, 100°] |
Working range | [-55, 125] °C | |
Interface | I2C | |
Power supply | [2.7, 5.5] V | |
Packages | SOIC or MSOP (8pin) |
The TCN75 has two different temperature probes, the first one is calibrated for a supply voltage of 3,3 V and the second one calibrated for a supply voltage of 5V. Both the probes can be used with different values of the supply voltage, but in this case the accuracy decreases up to +-3 °C following this rule: 1°C/V.
To work properly with the TCN75 we have to access 5 registers. (See the TCN75 datasheets for more information).
1. POINTER REGISTER
It is a 8-bit Write Only register and it is used to address one of the 4 following registers (D0 and D1, D2 to D7 must be set to zero)
D[7] | D[6] | D[5] | D[4] | D[3] | D[2] | D[1] | D[0] |
Must be set to 0 | Pointer |
Register Selection via the Pointer Register | ||
D[1] | D[0] | Register Selection |
0 | 0 | TEMP |
0 | 1 | CONFIG |
1 | 0 | T_HYST |
1 | 1 | T_SET |
2. CONFIGURATION REGISTER
It is a 8-bit Read/Write Register, it is used to configure next operation:
D[7] | D[6] | D[5] | D[4] | D[3] | D[2] | D[1] | D[0] |
Must be set to 0 | Fault Queue | INT/CMPTR, Polarity | COMP/INT | Shutdown |
3. TEMPERATURE REGISTER
It is a 16-bit Read Only register. It contains the temperature after a conversion cycle.
4. SETPOINT REGISTER
It is a 16-bit Read/Write register, it contains the setpoint temperature.
5. HYSTERESIS REGISTER
It is a 16-bit Read/Write register, it contains the threshold value for the hysteresis.
Speaking to the device
To speak to the device we will use the functions defined for the Pic 12f1840 in this post.
void i2c_start(void) | sends the start bit |
void i2c_restart(void) | sends the restart bit |
void i2c_stop(void) | sends the stop bit |
void i2c_ack(void) | sends ACK |
void i2c_nack(void) | sends NACK |
void i2c_wr(unsigned char i2c_data) | |
unsigned char i2c_rd(void) |
Reading the Configuration Register
void tcn75_rd_8(unsigned char ucTcn75Reg) // reads an 8 bit register of the TCN75 { gucI2CError = 0 ; // zero the I2C error i2c_start() ; // start I2C communication i2c_wr(TCN75_I2C_ADDR_WR) ; // write DEVICE ADDR for TCN75 WRITES i2c_wr(ucTcn75Reg) ; // write the register ADDRESS i2c_restart() ; // RESTART for READS i2c_wr(TCN75_I2C_ADDR_RD) ; // send the DEVICE ADDRESS for TCN75 READS. gLSBI2C = i2c_rd() ; // read register i2c_nack() ; // NOACK from MASTER (last read byte) i2c_stop() ; // stop I2C communication }
Writing the Configuration Register
/** Configuration register write 8 bit */ void tcn75_wr_8(unsigned char ucTcn75Reg) // writes a 8 bit value in a TCN75 register { gucI2CError = 0 ; // zero the I2C error i2c_start() ; // start I2C communication i2c_wr(TCN75_I2C_ADDR_WR) ; // write DEVICE ADDR for TCN75 WRITES i2c_wr(ucTcn75Reg) ; // write the register's ADDRESS i2c_wr(gLSBI2C) ; // write byte variable in the register i2c_stop() ; // stop I2C communication }
Writing 16-bit registers
void tcn75_wr_16(unsigned char ucTcn75Reg) { gucI2CError = 0 ; // zero the I2C error i2c_start() ; // start I2C communication i2c_wr(TCN75_I2C_ADDR_WR) ; // write DEVICE ADDR for RTCC WRITES i2c_wr(ucTcn75Reg) ; // write the register's ADDRESS i2c_wr(gMSBI2C) ; // write byte variable in the register MOST SIGNIFICANT BIT i2c_wr(gLSBI2C) ; // write byte variable in the register LESS SIGNIFICANT BIT i2c_stop() ; // stop I2C communication }
Reading 16-bit registers
void tcn75_rd_16(unsigned char ucTcn75Reg) { gucI2CError = 0; // zero the I2C error i2c_start(); // start I2C communication i2c_wr(TCN75_I2C_ADDR_WR); // write DEVICE ADDR for TCN75 WRITES i2c_wr(ucTcn75Reg); // write the register ADDRESS POINTER BYTE i2c_restart(); // RESTART for READS i2c_wr(TCN75_I2C_ADDR_RD); // send the DEVICE ADDRESS for TCN75 READS. gMSBI2C = i2c_rd(); // read the MSB part of the register i2c_ack(); // Master ack gLSBI2C = i2c_rd(); // read the LSB part of register i2c_nack(); // NOACK from MASTER (last read byte) i2c_stop(); // stop I2C communication }
Enjoy,
Gg1.