This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

TMP102-Q1: Can't get the ALERT in HW pin and in SW readout ConfigRegister AL bit when the termperature > T_High limit

Part Number: TMP102-Q1
Other Parts Discussed in Thread: TMP102,

TMP102.c
/*
 *  ======== TMP102.c ========
 *  TMP102 APIs for initialization and use of the TMP102 peripheral
 *
 *  DO NOT EDIT - This file is generated by the SysConfig tool for
 *  the TI Sensors in this application.
 */

#include "../TMP102_Q1/TMP102.h"

#include <stddef.h>
#include <stdint.h>

#include "../TMP102_Q1/mcu_i2c.h"

#define TMP102_0_CONFIG_VALUE (TMP102_CONFIG_OS_DISABLE | \
                               TMP102_CONFIG_F_1FAULT | \
                               TMP102_CONFIG_POL_LOW | \
                               TMP102_CONFIG_TM_COMP | \
                               TMP102_CONFIG_SD_CC | \
                               TMP102_CONFIG_CR_4HZ | \
                               TMP102_CONFIG_EM_12BIT)
//#define TMP102_0_TLOW_VALUE 0x0010U /* Temperature Low Limit is 1 Celsius */
//#define TMP102_0_THIGH_VALUE 0x0680U /* Temperature High Limit is 104 Celsius */

//#define TMP102_0_THIGH_VALUE 0x0300U   /*48C*/
//#define TMP102_0_THIGH_VALUE 0x0280U    /*40*/
#define TMP102_0_TLOW_VALUE 0x0140U     /*20*/
#define TMP102_0_THIGH_VALUE 0x0190U     /*25*/


static TMP102_State TMP102_0_state = {
    /* CONFIG register */
    .config = TMP102_0_CONFIG_VALUE,

    /* HIGH and LOW limit registers */
    .tHigh  = TMP102_0_THIGH_VALUE,
    .tLow   = TMP102_0_TLOW_VALUE,

    /* Sensor's I2C bus ID and address */
    .busId   = 0,
    .devAddr = 0x48U,

    /* one-shot delay time (ms) */
    .osWait  = 35
};
const TMP102_Handle TMP102_0 = &TMP102_0_state;

#define TMP102_1_CONFIG_VALUE (TMP102_CONFIG_OS_DISABLE | \
                               TMP102_CONFIG_F_1FAULT | \
                               TMP102_CONFIG_POL_HIGH | \
                               TMP102_CONFIG_TM_COMP | \
                               TMP102_CONFIG_SD_CC | \
                               TMP102_CONFIG_CR_4HZ | \
                               TMP102_CONFIG_EM_12BIT)
//#define TMP102_1_TLOW_VALUE 0x00A0U /* Temperature Low Limit is 10 Celsius */
//#define TMP102_1_THIGH_VALUE 0x0500U /* Temperature High Limit is 80 Celsius */
//#define TMP102_1_THIGH_VALUE 0x0300U   /*48C*/
//#define TMP102_1_THIGH_VALUE 0x0280U    /*40*/
#define TMP102_1_TLOW_VALUE 0x0140U     /*20*/
#define TMP102_1_THIGH_VALUE 0x0190U     /*25*/


static TMP102_State TMP102_1_state = {
    /* CONFIG register */
    .config = TMP102_1_CONFIG_VALUE,

    /* HIGH and LOW limit registers */
    .tHigh  = TMP102_1_THIGH_VALUE,
    .tLow   = TMP102_1_TLOW_VALUE,

    /* Sensor's I2C bus ID and address */
    .busId   = 0,
    .devAddr = 0x49U,

    /* one-shot delay time (ms) */
    .osWait  = 35
};
const TMP102_Handle TMP102_1 = &TMP102_1_state;

#define TMP102_2_CONFIG_VALUE (TMP102_CONFIG_OS_DISABLE | \
                               TMP102_CONFIG_F_1FAULT | \
                               TMP102_CONFIG_POL_LOW | \
                               TMP102_CONFIG_TM_COMP | \
                               TMP102_CONFIG_SD_CC | \
                               TMP102_CONFIG_CR_4HZ | \
                               TMP102_CONFIG_EM_12BIT)
#define TMP102_2_TLOW_VALUE 0x00A0U /* Temperature Low Limit is 10 Celsius */
//#define TMP102_2_THIGH_VALUE 0x0500U /* Temperature High Limit is 80 Celsius */
//#define TMP102_2_THIGH_VALUE 0x0300U   /*48C*/
#define TMP102_2_THIGH_VALUE 0x0280U    /*40*/


static TMP102_State TMP102_2_state = {
    /* CONFIG register */
    .config = TMP102_2_CONFIG_VALUE,

    /* HIGH and LOW limit registers */
    .tHigh  = TMP102_2_THIGH_VALUE,
    .tLow   = TMP102_2_TLOW_VALUE,

    /* Sensor's I2C bus ID and address */
    .busId   = 0,
    .devAddr = 0x4AU,

    /* one-shot delay time (ms) */
    .osWait  = 35
};
const TMP102_Handle TMP102_2 = &TMP102_2_state;

#define TMP102_3_CONFIG_VALUE (TMP102_CONFIG_OS_DISABLE | \
                               TMP102_CONFIG_F_1FAULT | \
                               TMP102_CONFIG_POL_LOW | \
                               TMP102_CONFIG_TM_COMP | \
                               TMP102_CONFIG_SD_CC | \
                               TMP102_CONFIG_CR_4HZ | \
                               TMP102_CONFIG_EM_12BIT)
#define TMP102_3_TLOW_VALUE 0x00A0U /* Temperature Low Limit is 10 Celsius */
#define TMP102_3_THIGH_VALUE 0x0500U /* Temperature High Limit is 80 Celsius */

static TMP102_State TMP102_3_state = {
    /* CONFIG register */
    .config = TMP102_3_CONFIG_VALUE,

    /* HIGH and LOW limit registers */
    .tHigh  = TMP102_3_THIGH_VALUE,
    .tLow   = TMP102_3_TLOW_VALUE,

    /* Sensor's I2C bus ID and address */
    .busId   = 0,
    .devAddr = 0x4BU,

    /* one-shot delay time (ms) */
    .osWait  = 35
};
const TMP102_Handle TMP102_3 = &TMP102_3_state;


#define MSB(u16) (((u16) & 0xFF00U) >> 8)
#define LSB(u16) ((u16) & 0xFFU)

/*
 *  ======== writeReg ========
 */
static void writeReg(TMP102_Handle sensor, int regAddr, uint16_t value)
{
    uint8_t txBuf[3];

    txBuf[0] = regAddr;
    txBuf[1] = MSB(value);
    txBuf[2] = LSB(value);
    mcu_i2cTransfer(sensor->busId, sensor->devAddr, txBuf, 3, NULL, 0);
}

/*
 *  ======== TMP102_config ========
 * Configure device with current settings.
 */
void TMP102_config(TMP102_Handle sensor)
{
    /* Initialize the bus containing this sensor */
    mcu_i2cInit(sensor->busId);

    /* Write sensor Configuration Register */
    writeReg(sensor, TMP102_CONFIG, sensor->config);

    /* Write sensor Temperature High and Low Registers */
    writeReg(sensor, TMP102_THIGH, sensor->tHigh);
    writeReg(sensor, TMP102_TLOW, sensor->tLow);
}

/*
 *  ======== TMP102_read ========
 *  Read temperature register
 */
int32_t TMP102_read(TMP102_Handle sensor)
{
    uint8_t txBuf[1];
    uint8_t rxBuf[2];
    int32_t tmp;

    /* If needed, setup one shot measurement */
    if (sensor->config & TMP102_CONFIG_SD_SD) {
        /* Reset one shot enable */
        writeReg(sensor, TMP102_CONFIG, sensor->config | TMP102_CONFIG_OS_ENABLE);

        /* Wait for conversion to complete */
        mcu_msWait(sensor->osWait);
    }

    /* Read temperature register */
    txBuf[0] = TMP102_TEMP;
    mcu_i2cTransfer(sensor->busId, sensor->devAddr, txBuf, 1, rxBuf, 2);

    /* Sign extend and combine MSB with LSB */
    tmp = (((int32_t)(int8_t)rxBuf[0]) << 8) | rxBuf[1];

    return (tmp);
}


/*
 *  ======== TMP102_toIntCelsius ========
 *  Convert raw temperature register value to degrees Celsius rounded to the
 *  nearest integer
 */
int32_t TMP102_toIntCelsius(TMP102_Handle sensor, int32_t x)
{
    /* Shift raw register value, based on config, to form a Q4 value */
    x >>= (sensor->config & (uint8_t)(TMP102_CONFIG_EM_13BIT)) ? 3 : 4;

    /* Optional: Add bias to round before the final truncation */
    x += (x >= 0) ? (1 << 3) : -(1 << 3);

    /* Convert Q4 value to whole number */
    x /= 1 << 4; /* use division so small negative values round to 0 */

    return x;
}

/*
 *  ======== TMP102_toMilliCelsius ========
 *  Convert raw temperature register value to milli-degrees Celsius
 */
int32_t TMP102_toMilliCelsius(TMP102_Handle sensor, int32_t x)
{
    /* Shift raw register value, based on config, to form a Q4 value */
    x >>= (sensor->config & (uint8_t)(TMP102_CONFIG_EM_13BIT)) ? 3 : 4;

    /* Scale to milli-degrees, convert Q4 value to a whole number */
    return ((1000 * x) >> 4);
}

/*
 *  ======== TMP102_toFloatCelsius ========
 *  Convert raw temperature register value to degrees Celsius
 */
float TMP102_toFloatCelsius(TMP102_Handle sensor, int32_t x)
{
    /* Shift raw register value, based on config, to form a Q4 value */
    x >>= (sensor->config & (uint8_t)(TMP102_CONFIG_EM_13BIT)) ? 3 : 4;

    /* Convert Q4 value to a float */
    return ((float)x * 0.0625f);
}


/*
 *  ======== TMP102_read ========
 *  Read configuration register
 */
int32_t TMP102_readConfigReg(TMP102_Handle sensor)
{
    uint8_t txBuf[1];
    uint8_t rxBuf[2];
    int32_t tmp;


    /* Read configuration register */
    txBuf[0] = TMP102_CONFIG;
    mcu_i2cTransfer(sensor->busId, sensor->devAddr, txBuf, 1, rxBuf, 2);

    /* Sign extend and combine MSB with LSB */
    tmp = (((int32_t)(int8_t)rxBuf[0]) << 8) | rxBuf[1];

    return (tmp);
}


/*Check if Alert for T(HIGH) is set
 * if set return 1. Otherwise return 0
  The AL bit is a read-only function. Reading the AL bit provides information
   about the comparator mode status
  The state of the POL bit inverts the polarity of data returned from the AL bit.
  When the POL bit equals 0, the AL bit reads as 1 until the temperature
  equals or exceeds T(HIGH) for the programmed number of consecutive faults,
  causing the AL bit to read as 0. The AL bit continues to read as 0 until
  the temperature falls below T(LOW) for the programmed number of consecutive
  faults, when it again reads as 1. The status of the TM bit does not affect the
  status of the AL bit.

  Parameter: x -- read result from configuration register

 */
uint8_t TMP102_TempHighAlert(TMP102_Handle sensor, int32_t x)
{
	uint8_t alert_ret = 0;  //no alert

    //TMP102_CONFIG_POL_HIGH 0x0400U
    //TMP102_CONFIG_AL_ENABLE 0x0020U

    //check if POL_HIGH/LOW
    if ((sensor->config & TMP102_CONFIG_POL_HIGH) == 0)
    {
        /* POL_LOW (default config), in this case
         *  if not,   AL bit=1
         *  if alert (Temp >=T_HIGH)  AL bit=0
         */
        if ((x & TMP102_CONFIG_AL_ENABLE) == 0)
        {
        	alert_ret  = 1;  //alert happen
        }
        //else no alert keep alert_ret=0
    }
    else
    {
        /* POL_HIGHT, in this case
         *  if not,   AL bit=0
         *  if alert (Temp >=T_HIGH)  AL bit=1
         */
        if ((x & TMP102_CONFIG_AL_ENABLE) == 1)
        {
        	alert_ret  = 1;  //alert happen
        }
        //else no alert keep alert_ret=0

    }

    return alert_ret;
}


/*  ======== TMP102_read ========
*  Read High-Limit register
*/
int32_t TMP102_THighReg(TMP102_Handle sensor)
{
   uint8_t txBuf[1];
   uint8_t rxBuf[2];
   int32_t tmp;


   /* Read High-Limit register */
   txBuf[0] = TMP102_THIGH;
   mcu_i2cTransfer(sensor->busId, sensor->devAddr, txBuf, 1, rxBuf, 2);

   /* Sign extend and combine MSB with LSB */
   tmp = (((int32_t)(int8_t)rxBuf[0]) << 8) | rxBuf[1];

   return (tmp);
}

/*  ======== TMP102_read ========
*  Read Low-Limit register
*/
int32_t TMP102_TLowReg(TMP102_Handle sensor)
{
   uint8_t txBuf[1];
   uint8_t rxBuf[2];
   int32_t tmp;


   /* Read Low-Limit register */
   txBuf[0] = TMP102_TLOW;
   mcu_i2cTransfer(sensor->busId, sensor->devAddr, txBuf, 1, rxBuf, 2);

   /* Sign extend and combine MSB with LSB */
   tmp = (((int32_t)(int8_t)rxBuf[0]) << 8) | rxBuf[1];

   return (tmp);
}
TMP102.h
test_TMP102-Q1.c
/*****************************************************************************
 *
 * test_TMP102-Q1.c
 *
 * Copyright 2020 Inceptio Technology. All Rights Reserved.
 *
 *****************************************************************************/

#include "console.h"

#include "../TMP102_Q1/mcu_i2c.h"  /* for mcu_msWait() */
#include "../TMP102_Q1/TMP102.h"


extern const TMP102_Handle TMP102_0;
extern const TMP102_Handle TMP102_1;
extern const TMP102_Handle TMP102_2;
extern const TMP102_Handle TMP102_3;


extern uint32 g_tmp102_testing_second;
uint8  g_hasTmp102Configured;

//for test
int32_t configReg_Ch[4];
int32_t THighReg_Ch[4];
int32_t TLowReg_Ch[4];

/*
 * This function is to test TMP102-Q1 sensors
 * by read these sensors per  second.
 *
 *   To start the test in console  Shell>
 *      pwr T   --- set running_tmp102_test= 1
 *
 *  To end the test in console  Shell>
 *     pwr Q   --- reset running_tmp102_test= 0
 */
int TMP102_Q1_test(void)
{
	int32_t tmp1020Temp;
	int32_t tmp1020TempAsIntCelsius;
	int32_t tmp1020TempAsMilliCelsius;
//	float tmp1020TempAsFloatCelsius;

	int32_t tmp1021Temp;
	int32_t tmp1021TempAsIntCelsius;
	int32_t tmp1021TempAsMilliCelsius;
//	float tmp1021TempAsFloatCelsius;

	int32_t tmp1022Temp;
	int32_t tmp1022TempAsIntCelsius;
	int32_t tmp1022TempAsMilliCelsius;
//	float tmp1022TempAsFloatCelsius;

	int32_t tmp1023Temp;
	int32_t tmp1023TempAsIntCelsius;
	int32_t tmp1023TempAsMilliCelsius;
//	float tmp1023TempAsFloatCelsius;

    int32_t configReg=0;
    uint8_t alert = 0;

    // call config only once
    if (g_hasTmp102Configured == 0)
    {
        /* init sensors with values specified in ti_sensors_config.c */
    	Ifx_Console_print("TMP102-Q1 sensors is being initializing. WAIT........\r\n");
        TMP102_config(TMP102_0);
        TMP102_config(TMP102_1);
        TMP102_config(TMP102_2);
        TMP102_config(TMP102_3);
        Ifx_Console_print("........Done init TMP102-Q1 sensors.  Ready to monitor temperatures\r\n");
        g_hasTmp102Configured = 1;
    }

    /* Note: in continuous modes (CC), polling rate should
     *       not exceed sensor conversion rate
     */
    mcu_msWait(1000); /* delay 1 sec */

    Ifx_Console_print("-------Monitoring TMP102 Sensors Second%d ------------------------\r\n", g_tmp102_testing_second++);

    /* Read TMP102_0 temp */
    tmp1020Temp = TMP102_read(TMP102_0);
    tmp1020TempAsIntCelsius = TMP102_toIntCelsius(TMP102_0, tmp1020Temp);
    tmp1020TempAsMilliCelsius = TMP102_toMilliCelsius(TMP102_0, tmp1020Temp);
    THighReg_Ch[0] = TMP102_THighReg(TMP102_0);
    TLowReg_Ch[0] = TMP102_TLowReg(TMP102_0);
    configReg_Ch[0] = TMP102_readConfigReg(TMP102_0);
    alert = TMP102_TempHighAlert(TMP102_0, configReg);
//    tmp1020TempAsFloatCelsius = TMP102_toFloatCelsius(TMP102_0, tmp1020Temp);
    Ifx_Console_print("TempSenor0: TempAsIntCelsius=%d, TempAsMilliCelsius=%d, Alert=%d\r\n",
        tmp1020TempAsIntCelsius, tmp1020TempAsMilliCelsius, alert);
        //Aurix console_print not support float printout for now

    /* Read TMP102_1 temp */
    tmp1021Temp = TMP102_read(TMP102_1);
    tmp1021TempAsIntCelsius = TMP102_toIntCelsius(TMP102_1, tmp1021Temp);
    tmp1021TempAsMilliCelsius = TMP102_toMilliCelsius(TMP102_1, tmp1021Temp);
    THighReg_Ch[1] = TMP102_THighReg(TMP102_1);
    TLowReg_Ch[1] = TMP102_TLowReg(TMP102_1);
    configReg_Ch[1] = TMP102_readConfigReg(TMP102_1);
    alert = TMP102_TempHighAlert(TMP102_1, configReg);
//    tmp1021TempAsFloatCelsius = TMP102_toFloatCelsius(TMP102_1, tmp1021Temp);
    Ifx_Console_print("TempSenor1: TempAsIntCelsius=%d, TempAsMilliCelsius=%d, Alert=%d\r\n",
        tmp1021TempAsIntCelsius, tmp1021TempAsMilliCelsius, alert);

    /* Read TMP102_2 temp */
    tmp1022Temp = TMP102_read(TMP102_2);
    tmp1022TempAsIntCelsius = TMP102_toIntCelsius(TMP102_2, tmp1022Temp);
    tmp1022TempAsMilliCelsius = TMP102_toMilliCelsius(TMP102_2, tmp1022Temp);
    THighReg_Ch[2] = TMP102_THighReg(TMP102_2);
    TLowReg_Ch[2] = TMP102_TLowReg(TMP102_2);
    configReg_Ch[2] = TMP102_readConfigReg(TMP102_2);
    alert = TMP102_TempHighAlert(TMP102_2, configReg);

//    tmp1022TempAsFloatCelsius = TMP102_toFloatCelsius(TMP102_2, tmp1022Temp);
    Ifx_Console_print("TempSenor2: TempAsIntCelsius=%d, TempAsMilliCelsius=%d, Alert=%d\r\n",
        tmp1022TempAsIntCelsius, tmp1022TempAsMilliCelsius, alert);


    /* Read TMP102_3 temp */
    tmp1023Temp = TMP102_read(TMP102_3);
    tmp1023TempAsIntCelsius = TMP102_toIntCelsius(TMP102_3, tmp1023Temp);
    tmp1023TempAsMilliCelsius = TMP102_toMilliCelsius(TMP102_3, tmp1023Temp);
    THighReg_Ch[3] = TMP102_THighReg(TMP102_3);
    TLowReg_Ch[3] = TMP102_TLowReg(TMP102_3);
    configReg_Ch[3] = TMP102_readConfigReg(TMP102_3);
    alert = TMP102_TempHighAlert(TMP102_3, configReg);

//    tmp1023TempAsFloatCelsius = TMP102_toFloatCelsius(TMP102_3, tmp1023Temp);
    Ifx_Console_print("TempSenor3:TempAsIntCelsius=%d, TempAsMilliCelsius=%d, Alert=%d\r\n",
         tmp1023TempAsIntCelsius, tmp1023TempAsMilliCelsius, alert);

    return 0;
}
mcu_i2c.c
/*
 *  Include Generic Header Files Here
 */

#include <stdio.h>
#include <stdint.h>
#include <stdbool.h>
#include <Cpu/Std/IfxCpu.h>
/*
 *  Include AURIX I2C  Specific Header Files Here
 */

#if !defined (BUILD_B_BOARD)
#include "brd_gpio_power.h"  /* for wait_us() */
#else
#define wait_us(x) wait(x*100)
#endif

#include "i2c_basic.h"             /* i2c HW related */
#include "console.h"           /*Ifx_Console_print show info in serial console for debugging */

#include "../TMP102_Q1/mcu_i2c.h"

/* Normally our I2Cs have been initialized by calling
 *    AduBoardInit in CPu0_Main.c
 *   If not, we just init I2C0 for TMP102 on ADU
 *
 *   Note:  In our ADU,  TMP102 devices are connected to I2C0
 *
 *   in below code, mcu is AURIX and I2C bus is 0
 */
#define I2C_HAVE_BEEN_INIT    1

//below flag is to use to make the I2C0 only init once
static uint8_t i2c_driverHasInit = 0;



/********* MCU  SPECIFIC I2C CODE STARTS HERE**********/

 /*  Initialize the specified I2C bus for first use
 */
void mcu_i2cInit(uint8_t busId)
{
    /* Add MCU specific init necessary for I2C to be used */

#ifndef I2C_HAVE_BEEN_INIT
	//Only init I2C0 once
	if (i2c_driverHasInit)
	{
		return;
	}

	uint8_t i2c_Bus = busId;
	/* In our ADU,  TMP102 devices are connected to I2C0 */
	if (busId != 0)
	{
		Ifx_Console_print("Warning mcu_i2cInit() TMP102 I2C is not in I2C Bus0. i2c_Bus=%d.  ADU force it=0\n\r",i2c_Bus);
		i2c_Bus = 0;   /* force I2Cbus = 0*/
	}

    /* disable interrupts */
    boolean   interruptState = IfxCpu_disableInterrupts();

    g_i2c0.i2cAddr = 0x48;   // init to one value, could be many different one

    {   /* init Module */
        IfxI2c_I2c_Config config;
        // i2c0
       IfxI2c_I2c_initConfig(&config, &MODULE_I2C0);
       const IfxI2c_Pins pins = {&IfxI2c0_SCL_P15_4_INOUT, &IfxI2c0_SDA_P15_5_INOUT, IfxPort_PadDriver_ttlSpeed1};
        config.pins     = &pins;
        config.baudrate = 400000;       /* 400 kHz */

        IfxI2c_I2c_initModule(&g_i2c0.i2c, &config);
    }
    {     /* init slave devices */
        IfxI2c_I2c_deviceConfig i2cDeviceConfig;
        IfxI2c_I2c_initDeviceConfig(&i2cDeviceConfig, &g_i2c0.i2c); /* Device config for Bus of i2c handle */

        i2cDeviceConfig.deviceAddress = g_i2c0.i2cAddr;
        IfxI2c_I2c_initDevice(&g_i2c0.i2cDev, &i2cDeviceConfig);
    }
    /* enable interrupts again */
    IfxCpu_restoreInterrupts(interruptState);

    //set flag to 1 and then the next time this function is call, not call init proceess again
    i2c_driverHasInit = 1;

#else
    // just to clean warning
    busId = busId;
    i2c_driverHasInit = 1;
    return;
#endif
}

/*
 *  ======== aurix_i2cTransfer ========
 *  Transfer data to and from an I2C slave
 *
 *  If writeLength is non-zero, mcu_i2cTransfer always performs the write
 *  transfer first.
 *
 *  @param busId         id of an I2C bus to access for the transfer
 *  @param sensorAddress I2C address of peripheral to access
 *  @param dataToWrite   non-NULL pointer to a buffer of at least writeLength
 *                       bytes; may be NULL if writeLength = 0.
 *  @param writeLength   number of bytes to write from the dataToWrite array
 *  @param dataToRead    non-NULL pointer to a buffer of at least readLength
 *                       bytes; may be NULL if readLength = 0.
 *  @param readLength    number of bytes to read into dataToRead array
 *
 *  @return              0 if successful, otherwise non-zero
 */
uint32    process_Cnt;   //change to local after testing
int8_t mcu_i2cTransfer( uint8_t busId, uint8_t i2cAddr,
                        uint8_t *dataToWrite, uint8_t writeLength,
                        uint8_t *dataToRead,  uint8_t readLength)
{
    /*
     *  Add MCU specific I2C read/write code here.
     */
	//uint32    process_Cnt;

	/*Calling parameter i2cAddr is 7 bit I2c address, like 0x48/49/4A/3B,  not include the last R/W bit
	 *  In Bit0  is 0 for Write,  IfxI2c_I2c_write
	 *                  1 for Read  IfxI2c_I2c_read
	 */
	uint8_t slavedev = i2cAddr << 1;

	//set I2C0 device address
	g_i2c0.i2cDev.deviceAddress = slavedev;

	uint8_t i2c_Bus = busId;
	/* In our ADU,  TMP102 devices are connected to I2C0 */
	if (busId != 0)
	{
		Ifx_Console_print("Warning mcu_i2cTransfer() TMP102 I2C is not in I2C Bus0. i2c_Bus=%d.  ADU force it=0\n\r",i2c_Bus);
		i2c_Bus = 0;   /* force I2Cbus = 0*/
	}

    //Write I2C
	if ( (dataToWrite != NULL)  && (writeLength != 0))
	{
	    process_Cnt = 0;
	    while (IfxI2c_I2c_write(&g_i2c0.i2cDev, dataToWrite,  writeLength) == IfxI2c_I2c_Status_nak)
	    {
	    	process_Cnt++;
	    	if  (process_Cnt > 100 )
	    	{
	    		Ifx_Console_print("Warning I2C0 WRITE  stuck in return Status_nak\r\n");
	    		break; // out of the loop.
	    	}
	    }
	}

    //Read I2C
	if ( (dataToRead != NULL)  && (readLength != 0))
	{
	    process_Cnt = 0;
	    while (IfxI2c_I2c_read(&g_i2c0.i2cDev, dataToRead,  readLength) == IfxI2c_I2c_Status_nak)
	    {
	    	process_Cnt++;
	    	if  (process_Cnt > 100 )
	    	{
	    		Ifx_Console_print("Warning I2C0 READ stuck in return Status_nak\r\n");
	    		break; // out of the loop.
	    	}
	    }
	}

    /*
     *  Add MCU specific return code for error handling
     */

    return (0);
}
/********* MCU SPECIFIC I2C CODE ENDS HERE**********/


/********* MCU SPECIFIC DELAY CODE ENDS HERE************/
void mcu_msWait(unsigned long msWait)
{
    /*
     *  Add MCU specific wait loop for msWait. The unit is in milli-seconds
     */
	wait_us(msWait * 1000);   //wait 1000 us = 1ms
}
/********* MCU SPECIFIC DELAY CODE ENDS HERE************/
mcu_i2c.h

I used TMP102_Q1 and code adapted from TI sample code site: https://dev.ti.com/sysconfig/index.html?product=ascstudio&module=/ti/sensors/tempsensor/TMP102#/config/?args=-s%20%2Fmnt%2Ftirex-content%2Fascstudio_1_0_5%2F.metadata%2Fproduct.json%20-d%20Other&module=%2Fti%2Fsensors%2Ftempsensor%2FTMP102

I can get temperature reading values correctly but can't get ALERT pin active when Temp exceeded T_High limit.   I use SW code read out Configuration Register and its AL bit can't be changed before/after temperature higher than T_High limit.   My configReg read out result is:(BIN) 0000 0000 0000 0000 0110 0000 1000 0000 for  before and after my test temperature higher than  T(HIGH)  Limit.  My expected result is after the temperature exceeded T(HIGH) Limit,   AL BIT (Bit 5 in LOW BYTE) should be changed  to (BIN) 0000 0000 0000 0000 0110 0000 1010 0000. 

Or based on this device's datasheet:

ConfigReg should be

    (BIN) 0000 0000 0000 0000 0110 0000 1010 0000 at normal temperature and after temperature >T_high,  ConfigReg should be changed to 

    (BIN) 0000 0000 0000 0000 0110 0000 1000 0000.

But my actual test result is  ConfigReg keep the same value (BIN) 0000 0000 0000 0000 0110 0000 1000 0000 before and after temperature >T_high. And I also checked  ALERT bin in HW board TMP102-Q1 device can't be changed before and after the temperature > T_High.

In my code:

-----------------------------------------------config---------------------------------------------------------------------------------------

#define TMP102_0_CONFIG_VALUE (TMP102_CONFIG_OS_DISABLE | \
                               TMP102_CONFIG_F_1FAULT | \
                               TMP102_CONFIG_POL_LOW | \
                               TMP102_CONFIG_TM_COMP | \
                               TMP102_CONFIG_SD_CC | \
                               TMP102_CONFIG_CR_4HZ | \
                               TMP102_CONFIG_EM_12BIT)
#define TMP102_0_TLOW_VALUE 0x0140U     /*20*/
#define TMP102_0_THIGH_VALUE 0x0190U     /*25*/

Besides functions from TI sample code site: https://dev.ti.com/sysconfig/index.html?product=ascstudio&module=/ti/sensors/tempsensor/TMP102#/config/?args=-s%20%2Fmnt%2Ftirex-content%2Fascstudio_1_0_5%2F.metadata%2Fproduct.json%20-d%20Other&module=%2Fti%2Fsensors%2Ftempsensor%2FTMP102,

My code to read config reg as:

/*
 *  ======== TMP102_read ========
 *  Read configuration register
 */
int32_t TMP102_readConfigReg(TMP102_Handle sensor)
{
    uint8_t txBuf[1];
    uint8_t rxBuf[2];
    int32_t tmp;


    /* Read configuration register */
    txBuf[0] = TMP102_CONFIG;
    mcu_i2cTransfer(sensor->busId, sensor->devAddr, txBuf, 1, rxBuf, 2);

    /* Sign extend and combine MSB with LSB */
    tmp = (((int32_t)(int8_t)rxBuf[0]) << 8) | rxBuf[1];

    return (tmp);
}

I attached all my files about this issue.

Thank you.

  • Hi Ling,

    You have four instances of TMP102 in your code, and only the device associated with TMP102_1_CONFIG_VALUE is being configured for POL_HIGH. Is this the cause of your confusion? 

    thanks,

    ren

  • Hi Ren,

    In you code, I just tried to use different POL_HIGH or POL_LOW to different temp sensors. In my hardware, we have 4 of these TMP sensors. No matter, I configured as POL_HIGH or POL_LOW, before and after my test temperatures over and under this corresponding TM sensor's T_HIGH, I can't see  any change in AL_bit in config Register neither in ALERT bit. 

    My expected result is when any TMP sensor's temperature is over T_High limit, AL_bit in configRegister and ALERT pin state should be changed to an opposite state as it's temperature is under T_Low limit no mater POL_HIGH or POL_LOW in configReg.

    Thank you.

    Ling

  • Ling,

    I've only been able to observe the AL bit change state due to a limit event while in Shutdown/One-Shot. I believe It's being cleared too quickly for us to observe in Continuous Conversion mode. I would recommend not relying on this bit to check ALERT status.

    thanks,

    ren