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.

HDC2010: CCS example for MSPM0L1306

Part Number: HDC2010
Other Parts Discussed in Thread: LP-MSPM0L1306, , MSPM0L1306, SYSCONFIG

Tool/software:

Hello Support-Team,

I assembled the HDC2010 on my product launchpad LP-MSPM0L1306 and now i am trying to get it worked. So, I am not using the EVM.

Is there somewhere an example code for the HDC2010 with the MSPM0L1306 (or another MCU from TI)?

I found these files attached to this question. Is there a latest updated version of these codes?

Thank you very much

Best regards
Maunil Chopra

/*
 *  ======== config.c ========
 *  Configuration-specific definitions
 *
 *  DO NOT EDIT - This file is generated by the SysConfig tool for
 *  the TI Sensors in this application.
 */
#include <stdint.h>

#include "HDC2010.h"

#include "config.h"

/*
 *  ======== HDC2010_0 ========
 *  HDC2010 Sensor configuration settings
 */
static HDC2010_State HDC2010_0_state = {
    .intConfig = (HDC2010_INT_CONFIG_DRDY_EN_DISABLE | \
                  HDC2010_INT_CONFIG_TH_EN_DISABLE | \
                  HDC2010_INT_CONFIG_TL_EN_DISABLE | \
                  HDC2010_INT_CONFIG_HH_EN_DISABLE | \
                  HDC2010_INT_CONFIG_HL_EN_DISABLE),
    .tempOffset = 0x00U,
    .humOffset = 0x00U,
    .tempThresLow = 0x00U,
    .tempThresHigh = 0xFFU,
    .humThresLow = 0x00U,
    .humThresHigh = 0xFFU,
    .config = (HDC2010_CONFIG_SOFT_RES_DISABLE | \
               HDC2010_CONFIG_AMM_DISABLED | \
               HDC2010_CONFIG_HEAT_EN_DISABLE | \
               HDC2010_CONFIG_DRDY_INT_EN_DISABLE | \
               HDC2010_CONFIG_INT_POL_LOW | \
               HDC2010_CONFIG_INT_MODE_LEVEL),
    .measConfig = (HDC2010_MEAS_CONFIG_TRES_14BIT | \
                   HDC2010_MEAS_CONFIG_HRES_14BIT | \
                   HDC2010_MEAS_CONFIG_MEAS_CONF_HT | \
                   HDC2010_MEAS_CONFIG_MEAS_TRIG_NA),

    /* I2C bus ID */
    .busId      = 0,

    /* Sensor address on the I2C bus */
    .devAddr    = 0x40U,

    /* Conversion time for temperature (in ms)  */
    .convWaitTemp = 1,

    /* Conversion time for humidity (in ms)  */
    .convWaitHum = 1,
};
const HDC2010_Handle HDC2010_0 = &HDC2010_0_state;

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

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

#include "HDC2010.h"
#include "mcu.h"

/*
 *  ======== HDC2010_config ========
 * Configure device with current settings.
 */
void HDC2010_config(HDC2010_Handle sensor)
{
    uint8_t  txBuf[9];

    /* Initialize the bus containing this sensor */
    mcu_i2cInit(sensor->busId);

    /* Write all eight registers 0x07 -> 0x0E in one transfer */
    txBuf[0] = HDC2010_INT_CONFIG;
    memcpy(&txBuf[1], &sensor->intConfig, 8);
    mcu_i2cTransfer(sensor->busId, sensor->devAddr,
                    txBuf, 9, NULL, 0);

    /* Write Measurement Configuration Register last (0x0F) */
    txBuf[0] = HDC2010_MEAS_CONFIG;
    if (sensor->config & HDC2010_CONFIG_AMM_MASK) {
        txBuf[1] = sensor->measConfig | HDC2010_MEAS_CONFIG_MEAS_TRIG_START;
    }
    else {
        txBuf[1] = sensor->measConfig;
    }  
    mcu_i2cTransfer(sensor->busId, sensor->devAddr, txBuf, 2, NULL, 0);
}

/*
 *  ======== HDC2010_read ========
 *  Read temperature and humidity registers
 */
void HDC2010_read(HDC2010_Handle sensor, uint32_t result[])
{
    uint8_t txBuf[2];
    uint8_t rxBuf[4] = {0};

    /* If AMM is disabled trigger conversion */
    if (!(sensor->config & HDC2010_CONFIG_AMM_MASK)) {
        /* Reset AMM to start measurement */
        txBuf[0] = HDC2010_MEAS_CONFIG;
        txBuf[1] = sensor->measConfig | HDC2010_MEAS_CONFIG_MEAS_TRIG_START;
        mcu_i2cTransfer(sensor->busId, sensor->devAddr, txBuf, 2, NULL, 0);

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

    /* Read registers, LOW and HIGH bytes */
    txBuf[0] = HDC2010_TEMP_LOW;
    mcu_i2cTransfer(sensor->busId, sensor->devAddr, txBuf, 1, rxBuf, 4);

    result[0] = (uint16_t)rxBuf[1] << 8 | rxBuf[0];
    result[1] = (uint16_t)rxBuf[3] << 8 | rxBuf[2];
}

/*
 *  ======== HDC2010_humRead ========
 *  Read humidity register
 */
uint16_t HDC2010_humRead(HDC2010_Handle sensor)
{
    uint8_t txBuf[2];
    uint8_t rxBuf[2] = {0};
    uint32_t hum;

    /* If AMM is disabled trigger conversion */
    if (!(sensor->config & HDC2010_CONFIG_AMM_MASK)) {
        /* Reset AMM to start measurement */
        txBuf[0] = HDC2010_MEAS_CONFIG;
        txBuf[1] = sensor->measConfig | HDC2010_MEAS_CONFIG_MEAS_TRIG_START;
        mcu_i2cTransfer(sensor->busId, sensor->devAddr, txBuf, 2, NULL, 0);

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

    /* Read humidity registers, LOW and HIGH bytes */
    txBuf[0] = HDC2010_HUM_LOW;
    mcu_i2cTransfer(sensor->busId, sensor->devAddr, txBuf, 1, rxBuf, 2);

    hum = (uint16_t)rxBuf[1] << 8 | rxBuf[0];

    return (hum);
}

/*
 *  ======== HDC2010_humToFloatRelative ========
 *  Convert humidity to a relative percentage
 */
float HDC2010_humToFloatRelative(uint16_t x)
{
    return ((float)x * (100.0f / 65536.0f));
}

/*
 *  ======== HDC2010_humToIntRelative ========
 *  Convert raw humidity register value to the relative humidity rounded
 *  to the nearest whole number; a range of 0 to 100.
 */
uint32_t HDC2010_humToIntRelative(uint16_t x)
{
    /* round relative humidity to nearest whole number */
    return ((25 * (uint32_t)x + 0x2000) >> 14);
}

/*
 *  ======== HDC2010_humToPermille ========
 *  Convert raw humidity register value to integral value equal to
 *  ten times the relative humidity
 */
uint32_t HDC2010_humToPermille(uint16_t x)
{
    /* compute (relative humidity * 10) and truncate to a whole number */
    return ((125 * (uint32_t)x) >> 13);
}

/*
 *  ======== HDC2010_tempRead ========
 *  Read temperature register
 */
uint16_t HDC2010_tempRead(HDC2010_Handle sensor)
{
    uint8_t txBuf[2];
    uint8_t rxBuf[2] = {0};
    uint16_t tmp;

    /* If AMM is disabled trigger conversion */
    if (!(sensor->config & HDC2010_CONFIG_AMM_MASK)) {
        /* Reset AMM to start measurement */
        txBuf[0] = HDC2010_MEAS_CONFIG;
        txBuf[1] = sensor->measConfig | HDC2010_MEAS_CONFIG_MEAS_TRIG_START;
        mcu_i2cTransfer(sensor->busId, sensor->devAddr, txBuf, 2, NULL, 0);

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

    /* Read temperature registers, LOW and HIGH */
    txBuf[0] = HDC2010_TEMP_LOW;
    mcu_i2cTransfer(sensor->busId, sensor->devAddr, txBuf, 1, rxBuf, 2);

    tmp = (uint16_t)rxBuf[1] << 8 | rxBuf[0];

    return (tmp);
}

/*
 *  ======== HDC2010_tempToFloatCelsius ========
 *  Convert temperature to celsius
 */
float HDC2010_tempToFloatCelsius(uint16_t x)
{
    return ((float)x * (165.0f / 65536.0f) - 40.0f);
}

/*
 *  ======== HDC2010_tempToIntCelsius ========
 *  Convert raw temperature register value to whole degrees Celsius
 */
int32_t HDC2010_tempToIntCelsius(uint16_t raw)
{
    int32_t x;

    /* add bias so truncation rounds to the nearest whole value */
    x = ((int32_t)raw * 165 + 32768) >> 16;

    /* shift result so result is Celsius */
    return (x - 40);
}

/*
 *  ======== HDC2010_tempToMilliCelsius ========
 *  Convert raw temperature register value to milli-degrees Celsius
 */
int32_t HDC2010_tempToMilliCelsius(uint16_t x)
{
    /* Scale conversion for milli-degrees and truncate rather than round */
    return ((20625 * (int32_t)x) >> 13) - 40000;
}
/*
 *  ======== main.c ========
 *  Simple example that uses the Sensors APIs
 */
#include "HDC2010.h"

#include "mcu.h"  /* for mcu_msWait() */

#include "config.h" /* for sensor handle names */

uint16_t hdc20100Temp;
float hdc20100TempAsFloatCelsius;
long int hdc20100TempAsIntCelsius;
long int hdc20100TempAsMilliCelsius;
uint16_t hdc20100Hum;
float hdc20100HumAsFloatRelative;
unsigned int hdc20100HumAsIntRelative;

/*
 *  ======== main ========
 */
int main(void)
{
    HDC2010_config(HDC2010_0);

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

        /* Read HDC2010_0 temperature */
        hdc20100Temp = HDC2010_tempRead(HDC2010_0);
        hdc20100TempAsFloatCelsius = HDC2010_tempToFloatCelsius(hdc20100Temp);
        hdc20100TempAsMilliCelsius = HDC2010_tempToMilliCelsius(hdc20100Temp);
        hdc20100TempAsIntCelsius = HDC2010_tempToIntCelsius(hdc20100Temp);

        /* Read HDC2010_0 humidity */
        hdc20100Hum = HDC2010_humRead(HDC2010_0);
        hdc20100HumAsFloatRelative = HDC2010_humToFloatRelative(hdc20100Hum);
        hdc20100HumAsIntRelative = HDC2010_humToIntRelative(hdc20100Hum);

    }
}
/*
 *  Include Generic Header Files Here
 */
#include <stdint.h>
#include <stdbool.h>
#include <stddef.h>

#include "mcu.h"

/*
 *  Include MCU Specific Header Files Here
 */

/*
 *  Include MCU Specific Header Files Here
 */

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

void mcu_i2cInit(uint8_t busId)
{
    /* Add MCU specific init necessary for I2C to be used */
}

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.
     */

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

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




/********* MCU SPECIFIC DELAY CODE STARTS HERE ************/
void mcu_msWait(uint16_t msWait)
{
    /*
     *  Add MCU specific wait loop for msWait. The unit is in milli-seconds
     */
}

void mcu_usWait(uint16_t usWait)
{
    /*
     *  Add MCU specific wait loop for usWait. The unit is in micro-seconds
     */
}
/********* MCU SPECIFIC DELAY CODE ENDS HERE ************/
mcu.h