8.8.3. TMP102 (TI)

8.8.3.1. Introduction

The TMP102 is a two-wire, serial output temperature sensor. Requiring no external components, the TMP102 is capable of reading temperatures to a resolution of 0.0625°C. The device is specified for operation over a temperature range of -40°C to +125°C.

8.8.3.2. Applications

The TMP102 is ideal for extended temperature measurement in a variety of communication, computer, consumer, environmental, industrial, and instrumentation applications. Applications include:

  • Portable and battery-powered applications
  • Power-supply temperature monitoring
  • Computer peripheral thermal protection
  • Notebook computers
  • Battery management
  • Office machines
  • Thermostat controls
  • Electromechanical device temperatures
  • Industrial Controls
  • Test Equipment
  • Medical Instrumentations

8.8.3.3. Resources

8.8.3.4. Platform Integration

The sensor can be enabled by defining compile-time flag PLTFRM_TMP102_TEMP_SENSOR_ENA. An example of using this sensor is illustrated in App Examples.

8.8.3.4.1. Functions

PLTFRM_sts_t TMP102_init(UINT8_t devId)

Initializes the device. This function is normally called during platform initialization. When the function returns, device is put in shutdown mode, which is updated in device context as TMP102_OPN_MODE_ONE_SHOT.

Parameters:
  • devId – Identity of the device.
Returns:

PLTFRM_STS_SUCCESS is returned on success. A non-zero value indicates a failure. One possible error is PLTFRM_STS_INV_DEV_ID.

PLTFRM_sts_t TMP102_startSingleConv(UINT8_t devId, SINT32_t *tempVal_p, UINT16_t *tmoVal_p)

Triggers sensing and conversion of temperature. If the device is in TMP102_OPN_MODE_PERIODIC mode, value is immediately read. If mode is TMP102_OPN_MODE_ONE_SHOT, conversion is started. A timeout value is returned to the caller so that the caller can read the value later when it becomes available.

Parameters:
  • devId – Identity of the device.
  • tempVal_p – Points to location where the temperature value is returned. Unit is milli celsius. Negative values are possible. This is applicable only in mode TMP102_OPN_MODE_PERIODIC.
  • tmoVal_p – Timeout value after which value will be available. This is applicable only in mode TMP102_OPN_MODE_ONE_SHOT.
Returns:

PLTFRM_STS_SUCCESS is returned on success. A non-zero value indicates a failure. Possible errors are PLTFRM_STS_INV_DEV_ID, PLTFRM_STS_INV_DEV_OPN_MODE, PLTFRM_STS_INV_PARAM and PLTFRM_STS_I2C_BUS_WR_ERROR.

PLTFRM_sts_t TMP102_getTempVal(UINT8_t devId, SINT32_t *tempVal_p)

Get the temperature value from the device.

Parameters:
  • devId – Identity of the device.
  • tempVal_p – Points to location where temperature value is returned. Unit is milli celsius. Negative values are possible.
Returns:

PLTFRM_STS_SUCCESS is returned on success. A non-zero value indicates a failure. Possible errors are PLTFRM_STS_INV_DEV_ID, PLTFRM_STS_INV_PARAM and PLTFRM_STS_I2C_BUS_WR_ERROR.

PLTFRM_sts_t TMP102_readReg(TMP102_cntxt_s *devCntxt_p, UINT8_t ptrRegVal, UINT8_t *rdBuff_p)

Reads a specified register from the device.

Parameters:
  • devId – Identity of the device.
  • ptrRegVal – Register to read. Possible values are TMP102_TEMP_REG_ADDR, TMP102_CONFIG_REG_ADDR, TMP102_LOW_TH_REG_ADDR and TMP102_HIGH_TH_REG_ADDR.
  • rdBuff_p – Points to buffer where the register value is returned.
Returns:

PLTFRM_STS_SUCCESS is returned on success. A non-zero value indicates a failure. Possible errors are PLTFRM_STS_INV_DEV_ID, PLTFRM_STS_INV_PARAM and PLTFRM_STS_I2C_BUS_WR_ERROR.

PLTFRM_sts_t TMP102_writeReg(TMP102_cntxt_s *devCntxt_p, UINT8_t ptrRegVal, UINT8_t *wrBuff_p)

Writes to a specified register for the purpose of device configuration. For example, this can be used to configure low and high thresholds for the temperature.

Parameters:
  • devId – Identity of the device.
  • ptrRegVal – Register to write. Possible values are TMP102_CONFIG_REG_ADDR, TMP102_LOW_TH_REG_ADDR and TMP102_HIGH_TH_REG_ADDR. Note that TMP102_TEMP_REG_ADDR is a read-only register.
  • wrBuff_p – Points to buffer where the register value is passed into this function. This is used to perform the write.
Returns:

PLTFRM_STS_SUCCESS is returned on success. A non-zero value indicates a failure. Possible errors are PLTFRM_STS_INV_DEV_ID, PLTFRM_STS_INV_PARAM and PLTFRM_STS_I2C_BUS_WR_ERROR.

8.8.3.4.2. Macros

#define TMP102_SENSOR_OUTPUT_VALUE_SZ   4


/*
 * The TMP102 features an address pin to allow up to four devices to
 * be addressed on a single bus. Table 12 describes the pin logic
 * levels used to properly connect up to four devices.
 */
#define TMP102_I2C_ADDR_PREFIX  0x48    // 0 1001 xxx

/*
 * Table 2. Pointer Addresses
 */
#define TMP102_TEMP_REG_ADDR      0x0   // RO
#define TMP102_CONFIG_REG_ADDR    0x1   // RW
#define TMP102_LOW_TH_REG_ADDR    0x2   // RW
#define TMP102_HIGH_TH_REG_ADDR   0x3   // RW

#define TMP102_TEMP_REG_SZ  0x2
#define TMP102_CONFIG_REG_SZ  0x2
#define TMP102_LOW_TH_REG_SZ  0x2
#define TMP102_HIGH_TH_REG_SZ  0x2


/*
 * Config register description
 * Table 7
 */
#define TMP102_CONFIG_REG_EM_BIT  (1 << 4)
#define TMP102_CONFIG_REG_AL_BIT  (1 << 5)
#define TMP102_CONFIG_REG_CR0_BIT (1 << 6)
#define TMP102_CONFIG_REG_CR1_BIT (1 << 7)

#define TMP102_CONFIG_REG_SD_BIT  (1 << 0)
#define TMP102_CONFIG_REG_TM_BIT  (1 << 1)
#define TMP102_CONFIG_REG_POL_BIT (1 << 2)
#define TMP102_CONFIG_REG_F0_BIT  (1 << 3)
#define TMP102_CONFIG_REG_F1_BIT  (1 << 4)
#define TMP102_CONFIG_REG_R0_BIT  (1 << 5)
#define TMP102_CONFIG_REG_R1_BIT  (1 << 6)
#define TMP102_CONFIG_REG_OS_BIT  (1 << 7)



/*
 * Bit D0 of byte 2 indicates Normal mode (EM bit = '0') or Extended
 * mode (EM bit = '1') and can be used to distinguish between the two
 * temperature register data formats.
 */
#define TMP102_TEMP_REG_MODE_BIT  (1 << 0)


/*
 * The TMP102 has a typical conversion time of 26ms. To achieve
 * different conversion rates, the TMP102 makes a conversion and
 * after that powers down and waits for the appropriate delay set
 * by CR1 and CR0.
 */
#define TMP102_CONVERSION_TIME_MILLISECS   26

8.8.3.4.3. Type Definitions

typedef enum
{
  TMP102_DATA_FMT_MODE_UNKNOWN =  0,
  TMP102_DATA_FMT_MODE_NORMAL = 1,   // EM - 0 (12 bit data)
  TMP102_DATA_FMT_MODE_EXTENDED = 2  // EM - 1 (13 bit data)
} TMP102_dataFmtMode_t;

/*
 * The conversion rate bits, CR1 and CR0, configure the TMP102 for
 * conversion rates of 8Hz, 4Hz, 1Hz, or 0.25Hz. The default rate
 * is 4Hz.
 */
typedef enum
{
   TMP102_CONV_RATE_QUARTER_HZ = 0,
   TMP102_CONV_RATE_ONE_HZ = 1,
   TMP102_CONV_RATE_FOUR_HZ = 2,
   TMP102_CONV_RATE_EIGHT_HZ = 3,
} TMP102_convRate_t;


/*
 * < SHUTDOWN MODE (SD) >
 * The Shutdown mode bit saves maximum power by shutting down all device
 * circuitry other than the serial interface, reducing current consumption
 * to typically less than 0.5 micro-amps. Shutdown mode is enabled when the
 * SD bit is '1'; the device shuts down when current conversion is completed.
 * When SD is equal to '0', the device maintains a continuous conversion state.
 *
 * After power-up or general-call reset, the TMP102 immediately starts a conversion.
 */
typedef enum
{
   TMP102_OPN_MODE_UNKNOWN = 0,
   TMP102_OPN_MODE_ONE_SHOT = 1,
   TMP102_OPN_MODE_PERIODIC = 2
} TMP102_opnMode_t;


typedef struct
{
   UINT8_t devId;
   TMP102_opnMode_t opnMode;
   TMP102_dataFmtMode_t dataFmtMode;
} TMP102_cntxt_s;