TMP112x - Temperature

Description

Library for interfacing Texas Instruments TMP112 family temperature sensors

The TMP112 family of devices are digital temperature sensors designed for high-accuracy, low-power, NTC/PTC thermistor replacements where high accuracy is required. -) I2C interface with communication speed up to 2.85 MHz -) Four user selectable addresses (chosen by chip pin) -) Temperature range: -40 to 125°C -) Resolution: 12 Bits (0.0625°C)

OVERVIEW

TMP112_Abstract:
This library can be used to handle Texas Instruments TMP112x temperature sensors.

Interfaces:
  • 1x I2C
  • 1x IRQ (optional)

  • The TMP112 family of devices are digital temperature sensors designed for high-accuracy,low-power, NTC/PTC thermistor replacements where high accuracy is required.
  • I2C interface with communication speed up to 2.85 MHz
  • Four user selectable addresses (chosen by chip pin)
  • Temperature range: -40 to 125°C
  • Resolution: 12 Bits (0.0625°C)
  • TMP112_How_to_use:
    /* Hardware setup */ const { PORT_I2C = 0, // The first I2C interface should be used. CHIP_ADDR = TMP112_I2C_ADR1 // I2C Address of the chip // (depends on the logic level at the chip's ADD0 pin) } /* Handles for available sensors */ new hTMP112[TTMP112_Handle]; // Handle to manage the TMP112 /* 1 sec. timer is used for the general program sequence */ #callback MainTimer() { // Init with "open loop" value to identify missing measurements // (temp simply stay unchanged in case of an error) static temp = S32_OL; // Temperature read from the TMP112 new err= TMP112_GetTemp(hTMP112, temp); // Reads the measured values ​​from the TMP112 // Issues temperature and return value of the TMP112_GetTemp function via the watch panel #watch( "temp_rh=%s°C %s", s32ToNamurStr( temp,2), errorToStr( err)); } main() { // Init I2C interface catch(rM2M_I2cInit(PORT_I2C, TMP112_CLOCK, 0)); // Initializes i2c communication with the TMP112 // PowerOn default settings are used (i.e. Continuos conversion with 4Hz update rate) catch(TMP112_Init(hTMP112, PORT_I2C, CHIP_ADDR)); // Note: "TMP112_Enable()" only needs to be called if the PowerOn defaults do not // match the requirements // Initialisation of a cyclic sec. timer setInterval(MainTimer, 1000); }

    BASIC

    TMP112_CLOCK -

    typical I2C clock speed to be used (400kHz, I2C Fast-Mode)

    TMP112_I2C_ADRx:

    Available TMP112 I2C addresses

    TMP112_I2C_ADR1 - Must be used if ADD0 (Pin 4) of the TMP112 is connected to Ground
    TMP112_I2C_ADR2 - Must be used if ADD0 (Pin 4) of the TMP112 is connected to V+
    TMP112_I2C_ADR3 - Must be used if ADD0 (Pin 4) of the TMP112 is connected to SDA
    TMP112_I2C_ADR4 - Must be used if ADD0 (Pin 4) of the TMP112 is connected to SCL
    TMP112_CONFIG_x:

    Configuration Register configuration bits

    TMP112_CONFIG_OS - bit15: Trigger One-Shot/ One-Shot conversion Ready
    write:
    1 - Triggers a single temperature conversion (Only when the device is in shutdown mode).
    The device returns to the shutdown state at the completion of the single conversion.
    read:
    0 - Single conversion in progress
    1 - Single conversion done
    TMP112_CONFIG_R_MSK - bit 13-14: Converter Resolution (Read Only)
    R0 and R1 are set to 11 on start up
    TMP112_CONFIG_F_x - bit 11-12: Number of fault conditions required to generate an alert
    TMP112_CONFIG_POL - bit10: Polarity of the ALERT pin output and the TMP112_CONFIG_AL bit
    0 - Active low (default)
    1 - Active high (i.e. the state of the ALERT pin is inverted)
    TMP112_CONFIG_TM - bit 9: Selecting Comperator mode or Interupt mode
    0 - Comparator mode (default)
    The Alert pin is activated when the temperature equals or exceeds THIGH and remains active until the temperature falls below the value in the TLOW.
    1 - Interrupt mode
    Tthe Alert pin is activated when the temperature exceeds THIGH) or goes below TLOW). The Alert pin is cleared when the host controller reads the temperature register.
    TMP112_CONFIG_SD - bit8: Shutting down all device circuitry other than the serial interface
    0 - Continuos conversion mode (default)
    1 - Shutdown mode (the device shuts down when current conversion is completed)
    TMP112_CONFIG_CR_x - bit 6-7: Conversion Rate Settings
    TMP112_CONFIG_AL - bit5: The Alert bit provides information about the comparator mode status (Read Only)
  • If the TMP112_CONFIG_POL bit is set, the data returned from the Alert bit is inverted.
  • The TMP112_CONFIG_TM bit does not affect the status of the Alert bit.
  • 0 - The temperature has met or exceeded THIGH for the programmed number of consecutive faults
    1 - The temperature has fallen below TLOW for the programmed number of consecutive faults
    TMP112_CONFIG_EM - bit4: Extended mode bit
    0 - Normal mode i.e. 12-bit data format is uses for temperature register and high and low limit registers (default)
    1 - Extended mode i.e. 13-bit data format is uses for temperature register and high and low limit registers
    TMP112_CONFIG_F_x:

    Number of fault conditions required to generate an alert (Configuration register, bit 11-12)

    A fault condition exists when the measured temperature exceeds the user-defined limits set in the THIGH and TLOW registers (see TMP112_REG_x).
    TMP112_CONFIG_F_1 - (0x0000 << 11): 1 Consecutive faults (default)
    TMP112_CONFIG_F_2 - (0x0001 << 11): 2 Consecutive faults
    TMP112_CONFIG_F_4 - (0x0002 << 11): 4 Consecutive faults
    TMP112_CONFIG_F_6 - (0x0003 << 11): 6 Consecutive faults
    TMP112_CONFIG_F_MSK - (0x1800): Bit mask for the "Number of fault conditions required to generate an alert" setting
    TMP112_CONFIG_CR_x:

    Conversion Rate Settings (Configuration register, bit 6-7)

    TMP112_CONFIG_CR_0_25Hz - (0x0000 << 6): 0.25 Hz
    TMP112_CONFIG_CR_1Hz - (0x0001 << 6): 1 Hz
    TMP112_CONFIG_CR_4Hz - (0x0002 << 6): 4 Hz (default)
    TMP112_CONFIG_CR_8Hz - (0x0003 << 6): 8 Hz
    TMP112_CONFIG_CR_MSK - (0x00C0): Conversion Rate Settings bit mask
    TMP112_Init(handle[TTMP112_Handle], i2c, addr)

    Initializes i2c communication with the TMP112 and prepares the TMP112 for use


    First copies the I2C port and address to the transferred empty device handle. Afterwards the configuration register is read to ensure that the TMP112 is present. Finally, the configuration register is set to PowerOn default settings (i.e. Continuos conversion mode with a conversion rate of 4Hz)

    handle : TTMP112_Handle - Empty device handle for a TMP112
    i2c : s32 - I2C interface where TMP112 is connected to
    The I2C interface must be initialisation before using rM2M_I2cInit().
    addr : s32 - I2C Address of the chip
    Use only the addresses specified under TMP112_I2C_ADRx
    returns : s32
    OK - if successful
    ERROR - if one of the following errors occurs
  • Unable to read configuration register
  • Configuration register could not be written
  • TMP112_Enable(handle[TTMP112_Handle], iConfig =-1)

    Activates the TMP112 by modifing the configuration register

    This function only needs to be called if the PowerOn defaults (see TMP112_CONFIG_x) do not match the requirements
    handle : TTMP112_Handle - Device handle of a specific TMP112 (Initialized by TMP112_Init() )
    iConfig : s32 - Configuration for the TMP112 (optional, use TMP112_CONFIG_x )
    -1 - Only the SD bit is cleared. All other bits of the configuration register remain unchanged
    >= 0 - Value to be written to the configuration register
    returns : s32
    OK - if successful
    ERROR - if one of the following errors occurs
  • Current contents of the configuration register could not be read
  • Configuration register could not be written
  • TMP112_TriggerSingleConversion(handle[TTMP112_Handle])

    Triggers a single conversion

    The conversion typically takes 26ms (max. 35ms). You can either use a fixed delay (e.g. using setTimeout ()) or check the bit TMP112_CONFIG_OS in the configuration register (see TMP112_CONFIG_x). To read the conversion results use TMP112_GetTemp().
    The TMP112 must be in Shutdown mode to be able to trigger a single conversion.
    handle : TTMP112_Handle - Device handle of a specific TMP112 (Initialized by TMP112_Init() )
    returns : s32
    OK - if successful
    ERROR - if one of the following errors occurs
  • Current contents of the configuration register could not be read
  • The TMP112 is not in shutdown mode
  • A single conversion is currently in progress
  • Configuration register could not be written
  • TMP112_GetTemp(handle[TTMP112_Handle], &iTemp)

    Reads temperature from the TMP112

    This function reads the TMP112 temperature register and converts the data. Themeasurement is returned in [0.01°C].
    handle : TTMP112_Handle - Device handle of a specific TMP112 (Initialized by TMP112_Init() )
    iTemp : s32 - Variable for storing the temperature value [0.01°C]
    returns : s32
    OK - if successful
    ERROR - if one of the following errors occurs
  • Current contents of the configuration register could not be read
  • Current contents of the Temperature register could not be read
  • TMP112_SetLimits(handle[TTMP112_Handle],iHigh, iLow, iMode=-1, iFaults=-1)

    Writes the temperature limits to the TLOW and THIGH registers of the TMP112. Optionally, it is also possible to specify whether the comperator mode or the interupt mode should be used, as well as the number of fault conditions required to generate an alert

    handle : TTMP112_Handle - Device handle of a specific TMP112 (Initialized by TMP112_Init() )
    iHigh : s32 - Value to be written to the THIGH register (higher temperature limit) [0.01°C]
    iLow : s32 - Value to be written to the TLOW register (lower temperature limit) [0.01°C]
    iMode : s32 - Selecting Comperator mode or Interupt mode (optional)
    -1 - The current setting is not changed
    0 - Comparator mode
    > 0 - Interrupt mode
    iFaults : s32 - Number of fault conditions required to generate an alert (optional, use TMP112_CONFIG_F_x)
    -1 - The current setting is not changed
    TMP112_CONFIG_F_x - The transferred value is adopted
    returns : s32
    OK - if successful
    ERROR - if one of the following errors occurs
  • Current contents of the configuration register could not be read
  • Configuration register could not be written
  • TLOW register could not be written
  • THIGH register could not be written
  • TMP112_GetLimits(handle[TTMP112_Handle],&iHigh, &iLow)

    Reads the current value of the temperature limits from the TMP112, which are stored in the TLOW and THIGH registers

    handle : TTMP112_Handle - Device handle of a specific TMP112 (Initialized by TMP112_Init() )
    iHigh : s32 - Variable for storing the higher temperature limit (THIGH) [0.01°C]
    iLow : s32 - Variable for storing the lower temperature limit (TLOW) [0.01°C]
    returns : s32
    OK - if successful
    ERROR - if one of the following errors occurs
  • Current contents of the configuration register could not be read
  • Current contents of the THIGH register could not be read
  • Current contents of the TLOW register could not be read
  • TMP112_Disable(handle[TTMP112_Handle])

    Sets the TMP112 into shutdown mode. (i.e. all device circuitry other than the serial interface are switched off) and thus grants minimum power consumption


    When accessing the configuration register, only the SD bit is set. All other bits of the register remain unchanged

    handle : TTMP112_Handle - Device handle of a specific TMP112 (Initialized by TMP112_Init() )
    returns : s32
    OK - if successful
    ERROR - if one of the following errors occurs
  • Current contents of the configuration register could not be read
  • Configuration register could not be written
  • EXPERT

    PCA9685_CLOCK_MAX -

    absolute maximum I2C clock speed (2.85MHz, I2C High-Speed-Mode)

    TMP112_REG_x:

    Pointer addresses of the registers available in the TMP112 (Address | R/W | Default | Description)

    TMP112_REG_TEMP - 0x00 | R | --- |
    Temperature Register (use TMP112_GetTemp())
    TMP112_REG_CONFIG - 0x01 | R/W | 0x60A0|
    Configuration Register (see TMP112_CONFIG_x)
    TMP112_REG_TEMP_LOW - 0x02 | R/W | 0x4B00 (i.e. +75°C in 12bit normal mode) |
    TLOW Register (use TMP112_SetLimits() or TMP112_GetLimits())
    TMP112_REG_TEMP_HIGH - 0x03 | R/W | 0x5000 (i.e. +80°C in 12bit normal mode) |
    THIGH Temperature Register (use TMP112_SetLimits() or TMP112_GetLimits())
    TMP112_Read(handle[TTMP112_Handle], Reg, &iValue)

    Reads a value from a TMP112 register


    This function checks the given register and converts the byte array to be read into a s32 cell. The first byte after slave address containing pointer address information is sent to the TMP112. After that, the TMP112 responds with the requested data frames after the second slave address byte. See the read word format in the datasheet for the timing diagrams.

    handle : TTMP112_Handle - Device handle of a specific TMP112 (Initialized by TMP112_Init() )
    Reg : s32 - TMP112 register (Pointer Address, use TMP112_REG_x)
    iVaulue : s32 - Variable for storing the data read from the TMP112
    returns : s32
    OK - if successful
    ERROR - if one of the following errors occurs
  • Pointer Address contained in Reg is invalid
  • if another error occurs
  • TMP112_Write(handle[TTMP112_Handle], Reg, iValue)

    Writes a value to a TMP112 register


    This function checks the given register and converts the value to be written into an array of bytes. The first byte after slave address contains pointer address information, followed by the actual data to be written. See the write word format in the datasheet for the timing diagrams.

    handle : TTMP112_Handle - Device handle of a specific TMP112 (Initialized by TMP112_Init() )
    Reg : s32 - TMP112 register (Pointer Address, use TMP112_REG_x)
    iValue : s32 - Value to be written to the register
    returns : s32
    OK - if successful
    ERROR - if one of the following errors occurs
  • Register is read only
  • Pointer Address contained in Reg is invalid
  • < OK - if another error occurs

    On this page

    TMP112x - Temperature