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.

SIMPLELINK-CC13X0-SDK: SIMPLELINK-CC13X0-SDK

Part Number: SIMPLELINK-CC13X0-SDK
Other Parts Discussed in Thread: TMP116, SYSBIOS, TMP007, CC1310

I have a problem with the RF communication using the CC1310F64 4x4mm type chip with 3v, this chip interfaced with a , the code developed and loaded on this chip works with the sensor (Presence of the SDA and SCL signal) but the emmision RF does not work, for the reception I use Smart RFstudio 7 - see attached the code n ° 1.

Before inserting the i2c parmetres and the TMP 116, the RF is working properly and sending data- see the attached code # 2.

Thank you in advance for your help.

4062.TMP116-i2c-CC1310F64-4X4mm-1.txt
/*
 * Copyright (c) 2015-2016, Texas Instruments Incorporated
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 *
 * *  Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 *
 * *  Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * *  Neither the name of Texas Instruments Incorporated nor the names of
 *    its contributors may be used to endorse or promote products derived
 *    from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

/*
 *  ======== rfEasyLinkTx.c ========
 */
/* XDCtools Header files */
#include <stdlib.h>
#include <xdc/std.h>
#include <xdc/runtime/System.h>
#include <xdc/runtime/Error.h>

#include <semaphore.h>

/* BIOS Header files */
#include <ti/drivers/rf/RF.h>
#include <ti/sysbios/BIOS.h>
#include <ti/sysbios/knl/Task.h>
#include <ti/sysbios/knl/Clock.h>

#include <ti/drivers/GPIO.h>
#include <ti/drivers/I2C.h>

/* TI-RTOS Header files */
#include <ti/drivers/PIN.h>
#include <ti/drivers/Power.h>

#include <ti/devices/cc13x0/driverlib/aon_batmon.h>
#include <ti/devices/cc13x0/driverlib/aux_adc.h>
#include <ti/devices/cc13x0/driverlib/chipinfo.h>
#include <ti/devices/cc13x0/driverlib/sys_ctrl.h>
#include <semaphore.h>
#include <ti/sail/tmp116/tmp116.h>
/* Board Header files */
#include "Board.h"

/* EasyLink API Header files */
#include "easylink/EasyLink.h"

#include "sc/scif.h"

#include "version.h"
#include "../sonde_gw_fw/sys_intf.h"

#include <string.h>
#include <math.h>

#define RFEASYLINKTX_TASK_STACK_SIZE    1024
#define RFEASYLINKTX_TASK_PRIORITY      2

#define RFEASYLINKTX_BURST_SIZE         1

Task_Struct txTask; /* not static so you can see in ROV */
static Task_Params txTaskParams;
static uint8_t txTaskStack[RFEASYLINKTX_TASK_STACK_SIZE];

Task_Struct sensorTask; /* not static so you can see in ROV */
static Task_Params sensorTaskParams;
static uint8_t sensorTaskStack[RFEASYLINKTX_TASK_STACK_SIZE];

TMP116_Handle  tmp116Handle ;
I2C_Handle     AppI2cHandle   ;
I2C_Transaction  i2cTransaction;
I2C_Params      AppI2cParams;
TMP116_Params  tmp116Params;
sem_t tmp116Sem;
float temp;

static PIN_State pinState;
static PIN_Handle pin_handle;


typedef struct {
    uint8_t     reason;
    int16_t     temp_deg_frac_8;
    uint8_t     bat_20mV;
} opto_sonde_data_t;

//const int OPTOSONDE_BROKEN_TEMP_SENSOR_THRESHOLD = 1500 * 1000; // 1.5 V
//#define OPTOSONDE_DEMO_MODE 1


PIN_Config pinTable[] = {
    PIN_ID(8) | PIN_INPUT_EN | PIN_PULLUP | PIN_HYSTERESIS,
    PIN_TERMINATE
};



void sleepAndReset(uint32_t sleep_time_secs) {

    // Enable button interrupt wake up
    PIN_setInterrupt(pin_handle, PIN_ID(8) | PIN_IRQ_NEGEDGE);

    uint32_t secs = sleep_time_secs;
    while (secs > 0)
    {
        uint32_t sleep_s = secs > 2000 ? 2000 : secs;
        Task_sleep((sleep_s * 1000u * 1000) / Clock_tickPeriod);
        secs -= sleep_s;
    }

    SysCtrlSystemReset();
}


void *tmp116AlertTask(void *arg0)
{
    uint16_t data;

    while(1) {

        /* Pend on semaphore, tmp116Sem */
        if (0 == sem_wait(&tmp116Sem)) {

            /* Reads status register, resetting the ALERT pin */
            TMP116_readStatus(tmp116Handle, &data);

        }
    }
}

static void rfEasyLinkTxFnx(UArg arg0, UArg arg1)
{

    opto_sonde_data_t* optosonde_data = (opto_sonde_data_t*) arg0;
//    rtc_cmd_t* rtc_cmd = arg1;

//    EasyLink_init(EasyLink_Phy_625bpsLrm);
//    EasyLink_init(EasyLink_Phy_5kbpsSlLr);
    EasyLink_init(EasyLink_Phy_Custom);

    /*
     * If you wish to use a frequency other than the default, use
     * the following API:
     * EasyLink_setFrequency(868000000);
     */

    /* Set output power to 12dBm */
//    EasyLink_setRfPwr(12);
    EasyLink_setRfPwr(10);

    EasyLink_TxPacket txPacket;

    // Fill packet data
    uint8_t payload_ptr = 0;
    // Payload version
    txPacket.payload[payload_ptr++] = (uint8_t) (0x0);
    // Src MAC
    EasyLink_getIeeeAddr(&txPacket.payload[payload_ptr]);
    payload_ptr += 8;

    // Copy data
    txPacket.payload[payload_ptr++] = (uint8_t) (optosonde_data->reason);
    txPacket.payload[payload_ptr++] = (uint8_t) (optosonde_data->temp_deg_frac_8 >> 8);
    txPacket.payload[payload_ptr++] = (uint8_t) (optosonde_data->temp_deg_frac_8);

    txPacket.payload[payload_ptr++] = (uint8_t) (optosonde_data->bat_20mV);

    // Firmware version
    memcpy(&txPacket.payload[payload_ptr], &VERSION_HASH, sizeof(VERSION_HASH));
    payload_ptr += sizeof(VERSION_HASH);

    txPacket.len = payload_ptr;
    txPacket.absTime = 0;
    txPacket.dstAddr[0] = OPTOSONDE_ADDR;

    EasyLink_Status result = EasyLink_transmit(&txPacket);

    if (result == EasyLink_Status_Success)
    {
        /* Toggle LED1 to indicate TX */
//                    PIN_setOutputValue(pinHandle, Board_PIN_LED1,!PIN_getOutputValue(Board_PIN_LED1));
    }
    else
    {
        /* Toggle LED1 and LED2 to indicate error */
//                    PIN_setOutputValue(pinHandle, Board_PIN_LED1,!PIN_getOutputValue(Board_PIN_LED1));
//                    PIN_setOutputValue(pinHandle, Board_PIN_LED2,!PIN_getOutputValue(Board_PIN_LED2));
    }

    // Prevent button reset overload
    if (optosonde_data->reason == optosonde_reason_button) {
        Task_sleep(1000000 / Clock_tickPeriod);
    }

    // Tell RTC to sleep
#ifdef OPTOSONDE_DEMO_MODE
    uint32_t sleep_time_s = 30;
#elif OPTOSONDE_VITICODE
    uint32_t sleep_time_s = 10 * 60;
#else
    uint32_t sleep_time_s = 1 * 3600;
#endif

    sleepAndReset(sleep_time_s);
}

void sendorTask_AlertCB()
{
    static opto_sonde_data_t optosonde_data;
    I2C_init();
    TMP116_init();

    /* Clear the ALERT interrupt source */
    scifClearAlertIntSource();

    /* Only handle the periodic event alert */
    if (scifGetAlertEvents() & (1 << SCIF_ADCMEAS_TASK_ID))
    {
        optosonde_data.reason = optosonde_reason_periodic;


        /* Get the SCE "output" structure */
        SCIF_ADCMEAS_OUTPUT_T* pOutput = scifGetTaskStruct(SCIF_ADCMEAS_TASK_ID, SCIF_STRUCT_OUTPUT);

        //GPIO_init();




       // GPIO_write(Board_TMP116_PWR, Board_TMP116_ON);

        I2C_Params_init(&AppI2cParams);
        AppI2cParams.transferMode = I2C_MODE_BLOCKING;
        AppI2cParams.transferCallbackFxn = NULL;
        AppI2cParams.bitRate = I2C_400kHz;
        AppI2cHandle = I2C_open(CC1310_LAUNCHXL_I2C0, NULL);
        if(AppI2cHandle == NULL){
            /* Error opening I2C */
            while (1);
        }

        TMP116_Params_init(&tmp116Params);

        /* Callback for ALERT event */

        tmp116Handle = TMP116_open(Board_TMP007_ROOMTEMP, AppI2cHandle, &tmp116Params);
        if (tmp116Handle == NULL) {

            while(1);
        }

        /* Allow the sensor hardware to complete its first conversion */



        TMP116_setTempLimit(tmp116Handle, TMP116_CELSIUS,(float)30.0F, (float)20.0F) ;

        /*int32_t adcVal_uV[5];
        int i;
        for (i = 0; i < 4; i++) {
            adcVal_uV[i] = AUXADCValueToMicrovolts(AUXADC_FIXED_REF_VOLTAGE_NORMAL, AUXADCAdjustValueForGainAndOffset(pOutput->ntcraw[i], AUXADCGetAdjustmentGain(AUXADC_REF_FIXED), AUXADCGetAdjustmentOffset(AUXADC_REF_FIXED)));
        }
        adcVal_uV[4] = 0;

        int validMeasIdx;

        for (validMeasIdx = 0; validMeasIdx < 4; validMeasIdx++) {
            if (adcVal_uV[validMeasIdx] > OPTOSONDE_BROKEN_TEMP_SENSOR_THRESHOLD) {
                if (validMeasIdx == 3) {
                    // Sensor is dead
                    optosonde_data.reason = optosonde_reason_sensorfail;
                }
            } else {
                break;
            }
        }

        const int32_t ptcR = adcVal_uV[validMeasIdx] / pOutput->ntcIuA[validMeasIdx];

        //const double ptcB25_100 = 3950;
        //const double rinf = 0.1763226979; // rinf = R0 * exp(-B/T0)

        //T = B / ln (R / rinf)
        //double ptcTemp = ptcB25_100 / log(ptcR / rinf) - 273.15;*/

        TMP116_getTemp(tmp116Handle, TMP116_CELSIUS, &temp);



        optosonde_data.temp_deg_frac_8 =(int16_t) temp*256 ;


        while (!AONBatMonNewBatteryMeasureReady())
        {
            // Wait
            Task_sleep(100 * 100 / Clock_tickPeriod);
        }
        optosonde_data.bat_20mV = (AONBatMonBatteryVoltageGet() * 390625) / 2000000;
        AONBatMonDisable();

        if (PIN_getInputValue(IOID_8) == 0) {
            optosonde_data.reason = optosonde_reason_button;
        }

        // Init Tx task
        Task_Params_init(&txTaskParams);
        txTaskParams.stackSize = RFEASYLINKTX_TASK_STACK_SIZE;
        txTaskParams.priority = RFEASYLINKTX_TASK_PRIORITY + 1;
        txTaskParams.stack = &txTaskStack;
        txTaskParams.arg0 = (xdc_UArg) &optosonde_data;

        Task_construct(&txTask, rfEasyLinkTxFnx, &txTaskParams, NULL);

    }
    else
    {
        // Sensor failed
        sleepAndReset(10 * 60);
    }

    /* Acknowledge the alert event */
    scifAckAlertEvents();
    scifUninit();
}

void sensorTask_fn(UArg arg0, UArg arg1)
{
    AONBatMonEnable();

    scifOsalInit();
    scifOsalRegisterTaskAlertCallback(sendorTask_AlertCB);
    scifInit(&scifDriverSetup);
    scifExecuteTasksOnceNbl(1 << SCIF_ADCMEAS_TASK_ID);
}

void pinInt(PIN_Handle handle, PIN_Id pinId) {
    if (pinId == 8) {
        // Force reset to trigger measure and TX
        SysCtrlSystemReset();
    }
}

/*
 *  ======== main ========
 */
int opto_main(void)
{
    /* Call driver init functions. */
    Board_initGeneral();
    pin_handle = PIN_open(&pinState, pinTable);
    PIN_registerIntCb(pin_handle, pinInt);
    // Sensor task
    Task_Params_init(&sensorTaskParams);
    txTaskParams.stackSize = RFEASYLINKTX_TASK_STACK_SIZE;
    txTaskParams.priority = RFEASYLINKTX_TASK_PRIORITY;
    txTaskParams.stack = &sensorTaskStack;
    txTaskParams.arg0 = 0;
    txTaskParams.arg1 = 0;

    Task_construct(&sensorTask, sensorTask_fn, &sensorTaskParams, NULL);


    /* Start BIOS */
    BIOS_start();

    return (0);
}

7776.TMP116-I2C-CC1310F64-4x4mm-2.txt
/*
 * Copyright (c) 2015-2016, Texas Instruments Incorporated
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 *
 * *  Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 *
 * *  Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * *  Neither the name of Texas Instruments Incorporated nor the names of
 *    its contributors may be used to endorse or promote products derived
 *    from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

/*
 *  ======== rfEasyLinkTx.c ========
 */
/* XDCtools Header files */
#include <stdlib.h>
#include <xdc/std.h>
#include <xdc/runtime/System.h>
#include <xdc/runtime/Error.h>

#include <semaphore.h>

/* BIOS Header files */
#include <ti/drivers/rf/RF.h>
#include <ti/sysbios/BIOS.h>
#include <ti/sysbios/knl/Task.h>
#include <ti/sysbios/knl/Clock.h>

#include <ti/drivers/GPIO.h>
#include <ti/drivers/I2C.h>

/* TI-RTOS Header files */
#include <ti/drivers/PIN.h>
#include <ti/drivers/Power.h>

#include <ti/devices/cc13x0/driverlib/aon_batmon.h>
#include <ti/devices/cc13x0/driverlib/aux_adc.h>
#include <ti/devices/cc13x0/driverlib/chipinfo.h>
#include <ti/devices/cc13x0/driverlib/sys_ctrl.h>
#include <semaphore.h>
#include <ti/sail/tmp116/tmp116.h>
/* Board Header files */
#include "Board.h"

/* EasyLink API Header files */
#include "easylink/EasyLink.h"

#include "sc/scif.h"

#include "version.h"
#include "../sonde_gw_fw/sys_intf.h"

#include <string.h>
#include <math.h>

#define RFEASYLINKTX_TASK_STACK_SIZE    1024
#define RFEASYLINKTX_TASK_PRIORITY      2

#define RFEASYLINKTX_BURST_SIZE         1

Task_Struct txTask; /* not static so you can see in ROV */
static Task_Params txTaskParams;
static uint8_t txTaskStack[RFEASYLINKTX_TASK_STACK_SIZE];

Task_Struct sensorTask; /* not static so you can see in ROV */
static Task_Params sensorTaskParams;
static uint8_t sensorTaskStack[RFEASYLINKTX_TASK_STACK_SIZE];

TMP116_Handle  tmp116Handle ;
I2C_Handle     AppI2cHandle   ;
I2C_Transaction  i2cTransaction;
I2C_Params      AppI2cParams;
TMP116_Params  tmp116Params;
sem_t tmp116Sem;
float temp;

static PIN_State pinState;
static PIN_Handle pin_handle;


typedef struct {
    uint8_t     reason;
    int16_t     temp_deg_frac_8;
    uint8_t     bat_20mV;
} opto_sonde_data_t;

//const int OPTOSONDE_BROKEN_TEMP_SENSOR_THRESHOLD = 1500 * 1000; // 1.5 V
//#define OPTOSONDE_DEMO_MODE 1


PIN_Config pinTable[] = {
    PIN_ID(8) | PIN_INPUT_EN | PIN_PULLUP | PIN_HYSTERESIS,
    PIN_TERMINATE
};



void sleepAndReset(uint32_t sleep_time_secs) {

    // Enable button interrupt wake up
    PIN_setInterrupt(pin_handle, PIN_ID(8) | PIN_IRQ_NEGEDGE);

    uint32_t secs = sleep_time_secs;
    while (secs > 0)
    {
        uint32_t sleep_s = secs > 2000 ? 2000 : secs;
        Task_sleep((sleep_s * 1000u * 1000) / Clock_tickPeriod);
        secs -= sleep_s;
    }

    SysCtrlSystemReset();
}


void *tmp116AlertTask(void *arg0)
{
    uint16_t data;

    while(1) {

        /* Pend on semaphore, tmp116Sem */
        if (0 == sem_wait(&tmp116Sem)) {

            /* Reads status register, resetting the ALERT pin */
            TMP116_readStatus(tmp116Handle, &data);

        }
    }
}

static void rfEasyLinkTxFnx(UArg arg0, UArg arg1)
{

    opto_sonde_data_t* optosonde_data = (opto_sonde_data_t*) arg0;
//    rtc_cmd_t* rtc_cmd = arg1;

//    EasyLink_init(EasyLink_Phy_625bpsLrm);
//    EasyLink_init(EasyLink_Phy_5kbpsSlLr);
    EasyLink_init(EasyLink_Phy_Custom);

    /*
     * If you wish to use a frequency other than the default, use
     * the following API:
     * EasyLink_setFrequency(868000000);
     */

    /* Set output power to 12dBm */
//    EasyLink_setRfPwr(12);
    EasyLink_setRfPwr(10);

    EasyLink_TxPacket txPacket;

    // Fill packet data
    uint8_t payload_ptr = 0;
    // Payload version
    txPacket.payload[payload_ptr++] = (uint8_t) (0x0);
    // Src MAC
    EasyLink_getIeeeAddr(&txPacket.payload[payload_ptr]);
    payload_ptr += 8;

    // Copy data
    txPacket.payload[payload_ptr++] = (uint8_t) (optosonde_data->reason);
    txPacket.payload[payload_ptr++] = (uint8_t) (optosonde_data->temp_deg_frac_8 >> 8);
    txPacket.payload[payload_ptr++] = (uint8_t) (optosonde_data->temp_deg_frac_8);

    txPacket.payload[payload_ptr++] = (uint8_t) (optosonde_data->bat_20mV);

    // Firmware version
    memcpy(&txPacket.payload[payload_ptr], &VERSION_HASH, sizeof(VERSION_HASH));
    payload_ptr += sizeof(VERSION_HASH);

    txPacket.len = payload_ptr;
    txPacket.absTime = 0;
    txPacket.dstAddr[0] = OPTOSONDE_ADDR;

    EasyLink_Status result = EasyLink_transmit(&txPacket);

    if (result == EasyLink_Status_Success)
    {
        /* Toggle LED1 to indicate TX */
//                    PIN_setOutputValue(pinHandle, Board_PIN_LED1,!PIN_getOutputValue(Board_PIN_LED1));
    }
    else
    {
        /* Toggle LED1 and LED2 to indicate error */
//                    PIN_setOutputValue(pinHandle, Board_PIN_LED1,!PIN_getOutputValue(Board_PIN_LED1));
//                    PIN_setOutputValue(pinHandle, Board_PIN_LED2,!PIN_getOutputValue(Board_PIN_LED2));
    }

    // Prevent button reset overload
    if (optosonde_data->reason == optosonde_reason_button) {
        Task_sleep(1000000 / Clock_tickPeriod);
    }

    // Tell RTC to sleep
#ifdef OPTOSONDE_DEMO_MODE
    uint32_t sleep_time_s = 30;
#elif OPTOSONDE_VITICODE
    uint32_t sleep_time_s = 10 * 60;
#else
    uint32_t sleep_time_s = 1 * 3600;
#endif

    sleepAndReset(sleep_time_s);
}

void sendorTask_AlertCB()
{
    static opto_sonde_data_t optosonde_data;
    //I2C_init();
    //TMP116_init();

    /* Clear the ALERT interrupt source */
    scifClearAlertIntSource();

    /* Only handle the periodic event alert */
    if (scifGetAlertEvents() & (1 << SCIF_ADCMEAS_TASK_ID))
    {
        optosonde_data.reason = optosonde_reason_periodic;


        /* Get the SCE "output" structure */
        SCIF_ADCMEAS_OUTPUT_T* pOutput = scifGetTaskStruct(SCIF_ADCMEAS_TASK_ID, SCIF_STRUCT_OUTPUT);

        //GPIO_init();




       // GPIO_write(Board_TMP116_PWR, Board_TMP116_ON);

        //I2C_Params_init(&AppI2cParams);
        //AppI2cParams.transferMode = I2C_MODE_BLOCKING;
        //AppI2cParams.transferCallbackFxn = NULL;
        //AppI2cParams.bitRate = I2C_400kHz;
        //AppI2cHandle = I2C_open(CC1310_LAUNCHXL_I2C0, NULL);
        //if(AppI2cHandle == NULL){
            /* Error opening I2C */
            //while (1);
        //}

        //TMP116_Params_init(&tmp116Params);

        /* Callback for ALERT event */

        //tmp116Handle = TMP116_open(Board_TMP007_ROOMTEMP, AppI2cHandle, &tmp116Params);
        //if (tmp116Handle == NULL) {

            //while(1);
        //}

        /* Allow the sensor hardware to complete its first conversion */



        //TMP116_setTempLimit(tmp116Handle, TMP116_CELSIUS,(float)30.0F, (float)20.0F) ;

        /*int32_t adcVal_uV[5];
        int i;
        for (i = 0; i < 4; i++) {
            adcVal_uV[i] = AUXADCValueToMicrovolts(AUXADC_FIXED_REF_VOLTAGE_NORMAL, AUXADCAdjustValueForGainAndOffset(pOutput->ntcraw[i], AUXADCGetAdjustmentGain(AUXADC_REF_FIXED), AUXADCGetAdjustmentOffset(AUXADC_REF_FIXED)));
        }
        adcVal_uV[4] = 0;

        int validMeasIdx;

        for (validMeasIdx = 0; validMeasIdx < 4; validMeasIdx++) {
            if (adcVal_uV[validMeasIdx] > OPTOSONDE_BROKEN_TEMP_SENSOR_THRESHOLD) {
                if (validMeasIdx == 3) {
                    // Sensor is dead
                    optosonde_data.reason = optosonde_reason_sensorfail;
                }
            } else {
                break;
            }
        }

        const int32_t ptcR = adcVal_uV[validMeasIdx] / pOutput->ntcIuA[validMeasIdx];

        //const double ptcB25_100 = 3950;
        //const double rinf = 0.1763226979; // rinf = R0 * exp(-B/T0)

        //T = B / ln (R / rinf)
        //double ptcTemp = ptcB25_100 / log(ptcR / rinf) - 273.15;*/

        //TMP116_getTemp(tmp116Handle, TMP116_CELSIUS, &temp);



        optosonde_data.temp_deg_frac_8 =(int16_t) temp*256 ;


        while (!AONBatMonNewBatteryMeasureReady())
        {
            // Wait
            Task_sleep(100 * 100 / Clock_tickPeriod);
        }
        optosonde_data.bat_20mV = (AONBatMonBatteryVoltageGet() * 390625) / 2000000;
        AONBatMonDisable();

        if (PIN_getInputValue(IOID_8) == 0) {
            optosonde_data.reason = optosonde_reason_button;
        }

        // Init Tx task
        Task_Params_init(&txTaskParams);
        txTaskParams.stackSize = RFEASYLINKTX_TASK_STACK_SIZE;
        txTaskParams.priority = RFEASYLINKTX_TASK_PRIORITY + 1;
        txTaskParams.stack = &txTaskStack;
        txTaskParams.arg0 = (xdc_UArg) &optosonde_data;

        Task_construct(&txTask, rfEasyLinkTxFnx, &txTaskParams, NULL);

    }
    else
    {
        // Sensor failed
        sleepAndReset(10 * 60);
    }

    /* Acknowledge the alert event */
    scifAckAlertEvents();
    scifUninit();
}

void sensorTask_fn(UArg arg0, UArg arg1)
{
    AONBatMonEnable();

    scifOsalInit();
    scifOsalRegisterTaskAlertCallback(sendorTask_AlertCB);
    scifInit(&scifDriverSetup);
    scifExecuteTasksOnceNbl(1 << SCIF_ADCMEAS_TASK_ID);
}

void pinInt(PIN_Handle handle, PIN_Id pinId) {
    if (pinId == 8) {
        // Force reset to trigger measure and TX
        SysCtrlSystemReset();
    }
}

/*
 *  ======== main ========
 */
int opto_main(void)
{
    /* Call driver init functions. */
    Board_initGeneral();
    pin_handle = PIN_open(&pinState, pinTable);
    PIN_registerIntCb(pin_handle, pinInt);
    // Sensor task
    Task_Params_init(&sensorTaskParams);
    txTaskParams.stackSize = RFEASYLINKTX_TASK_STACK_SIZE;
    txTaskParams.priority = RFEASYLINKTX_TASK_PRIORITY;
    txTaskParams.stack = &sensorTaskStack;
    txTaskParams.arg0 = 0;
    txTaskParams.arg1 = 0;

    Task_construct(&sensorTask, sensorTask_fn, &sensorTaskParams, NULL);


    /* Start BIOS */
    BIOS_start();

    return (0);
}

  • Hello Abdelkader,

    I see that you are initializing I2C and TMP116 in the callback function. Please note that the callback functions should be light weight and preferably should be used for setting flags or post semaphores. Heavy processing in callback will result in unexpected behavior(like the one you are seeing). Also how often do you think this callback function will be called? If more than once, you will be calling all the initialization code more than once.

    Please move the init code out of the callback. Also consider creating a separate task and post that task for processing in the callback rather than doing all the processing in the callback.

    You may also want to consider going through the TIRTOS training workshop training.ti.com/ti-rtos-workshop-series.

    Regards,
    Prashanth
  • Hi,
    thank you for your reply
    Can you show me how to do it, please ?, I tried but I can not transmit. thank you in advance.
  • Hello Abdelkader,

    Is this a university project? We suggest you try to figure it as a learning experience. Please go through the TI RTOS training material.

    Regards,
    Prashanth
  • thanks for your answer and advice,

    Yes, I am a student.

    I tried to find a solution to this problem but I have not arrived, I can not transmit my temperature data through RF.

    Indeed, I moved my sensor initialization parameters, but when I add the reading portion of the temperature, the RF does not work. And carrying I tested to send some parameters of the probe via RF including the address mac, the state of the battery ....

    Also, I tested the communication between the mictrotroller and the tmp116 sensor, there is an i2c communication (SDA, SCL).

    Please see the attached code, please.

    Sonde29042018.zip

  • Hello Abdelkader,
    From your code I see that you are constructing a Tx task in a call back function. This is not advisable. Callback functions should be treated as ISR routines with minimal processing like setting flags or posting semaphores. Can you move the task_construct out of the callback and try again. Also add a semaphore in the rfEasyLinkTxFnx and post that semaphore in the callback sendorTask_AlertCB.
    Regards,
    Prashanth
  • Sonde08052018.zipThank you you for your reply;

    I tested the RF part on my custom PCB that worked well, also for the part of the temperature sensor, but when integrating the two codes, I encountered a problem accessing the global variable called temp, the latter is modified by the thread and read by the task. as shown in the following code:

    ------------------------------------------------------------------------------------------------------------------------------the code-------------------

    /*

    *  ======== rfEasyLinkTx.c ========

    */

    /* XDCtools Header files */

    /* POSIX Header files */

    #include <pthread.h>

    #include <stdlib.h>

    #include <xdc/std.h>

    #include <xdc/runtime/System.h>

    #include <xdc/runtime/Error.h>

    #include <stdint.h>

    #include <stddef.h>

    #include <unistd.h>

    #include <semaphore.h>

    /* BIOS Header files */

    #include <ti/drivers/rf/RF.h>

    #include <ti/sysbios/BIOS.h>

    #include <ti/sysbios/knl/Task.h>

    #include <ti/sysbios/knl/Clock.h>

    #include <ti/drivers/GPIO.h>

    #include <ti/drivers/I2C.h>

    /* TI-RTOS Header files */

    #include <ti/drivers/PIN.h>

    #include <ti/drivers/Power.h>

    #include <ti/devices/cc13x0/driverlib/aon_batmon.h>

    #include <ti/devices/cc13x0/driverlib/aux_adc.h>

    #include <ti/devices/cc13x0/driverlib/chipinfo.h>

    #include <ti/devices/cc13x0/driverlib/sys_ctrl.h>

    #include <semaphore.h>

    #include <ti/sail/tmp116/tmp116.h>

    /* Board Header files */

    #include "Board.h"

    /* EasyLink API Header files */

    #include "easylink/EasyLink.h"

    #include "sc/scif.h"

    #include "version.h"

    #include "../sonde_gw_fw/sys_intf.h"

    #include <string.h>

    #include <math.h>

    #define RFEASYLINKTX_TASK_STACK_SIZE    1024

    #define RFEASYLINKTX_TASK_PRIORITY      2

    #define RFEASYLINKTX_BURST_SIZE         1

    /* Stack size in bytes */

    //#define THREADSTACKSIZE    768

    Task_Struct txTask; /* not static so you can see in ROV */

    static Task_Params txTaskParams;

    static uint8_t txTaskStack[RFEASYLINKTX_TASK_STACK_SIZE];

    Task_Struct sensorTask; /* not static so you can see in ROV */

    static Task_Params sensorTaskParams;

    static uint8_t sensorTaskStack[RFEASYLINKTX_TASK_STACK_SIZE];

    #define SAMPLE_TIME     1        /*In seconds*/

    #define THREADSTACKSIZE    768

    #define TMP_TASK_STACK_SIZE   768

    TMP116_Handle  tmp116Handle = NULL;

    I2C_Handle     i2cHandle    = NULL;

    sem_t tmp116Sem;

    sem_t datatmp;

    float temp ;

    int16_t datatosend;

    volatile uint16_t sampleTime;

    static PIN_State pinState;

    static PIN_Handle pin_handle;

    typedef struct {

       uint8_t     reason;

       int16_t      temp_deg_frac_8;

       uint8_t     bat_20mV;

    } opto_sonde_data_t;

    //const int OPTOSONDE_BROKEN_TEMP_SENSOR_THRESHOLD = 1500 * 1000; // 1.5 V

    //#define OPTOSONDE_DEMO_MODE 1

    PIN_Config pinTable[] = {

       PIN_ID(8) | PIN_INPUT_EN | PIN_PULLUP | PIN_HYSTERESIS,

       PIN_TERMINATE

    };

    /***********************i2c*******/

    void tmp116Callback(uint_least8_t index)

    {

       sem_post(&tmp116Sem);

    }

    void *tmp116AlertTask(void *arga)

    {

       uint16_t data;

       while(1) {

           /* Pend on semaphore, tmp116Sem */

           if (0 == sem_wait(&tmp116Sem)) {

               /* Reads status register, resetting the ALERT pin */

               TMP116_readStatus(tmp116Handle, &data);

               /* Check Object Temperature High Flag */

               if (data & TMP116_STAT_ALR_HI) {

               }

               /* Check Object Temperature Low Flag */

               if (data & TMP116_STAT_ALR_LO) {

               }

           }

       }

    }

    /***********************/

    void sleepAndReset(uint32_t sleep_time_secs) {

       // Enable button interrupt wake up

       PIN_setInterrupt(pin_handle, PIN_ID(8) | PIN_IRQ_NEGEDGE);

       uint32_t secs = sleep_time_secs;

       while (secs > 0)

       {

           uint32_t sleep_s = secs > 2000 ? 2000 : secs;

           Task_sleep((sleep_s * 1000u * 1000) / Clock_tickPeriod);

           secs -= sleep_s;

       }

       SysCtrlSystemReset();

    }

    static void rfEasyLinkTxFnx(UArg arg0, UArg arg1)

    {

       opto_sonde_data_t* optosonde_data = (opto_sonde_data_t*) arg0;

       EasyLink_init(EasyLink_Phy_Custom);

       /*

        * If you wish to use a frequency other than the default, use

        * the following API:

        * EasyLink_setFrequency(868000000);

        */

       /* Set output power to 12dBm */

    //    EasyLink_setRfPwr(12);

       EasyLink_setRfPwr(10);

       EasyLink_TxPacket txPacket;

       // Fill packet data

       uint8_t payload_ptr = 0;

       // Payload version

       txPacket.payload[payload_ptr++] = (uint8_t) (0x0);

       // Src MAC

       EasyLink_getIeeeAddr(&txPacket.payload[payload_ptr]);

       payload_ptr += 8;

       // Copy data

       txPacket.payload[payload_ptr++] = (uint8_t) (optosonde_data->reason);

       txPacket.payload[payload_ptr++] = (uint8_t) (optosonde_data->temp_deg_frac_8 >> 8);

       txPacket.payload[payload_ptr++] = (uint8_t) (optosonde_data->temp_deg_frac_8);

       txPacket.payload[payload_ptr++] = (uint8_t) (optosonde_data->bat_20mV);

       // Firmware version

       memcpy(&txPacket.payload[payload_ptr], &VERSION_HASH, sizeof(VERSION_HASH));

       payload_ptr += sizeof(VERSION_HASH);

       txPacket.len = payload_ptr;

       txPacket.absTime = 0;

       txPacket.dstAddr[0] = OPTOSONDE_ADDR;

       EasyLink_Status result = EasyLink_transmit(&txPacket);

       if (result == EasyLink_Status_Success)

       {

           /* Toggle LED1 to indicate TX */

    //                    PIN_setOutputValue(pinHandle, Board_PIN_LED1,!PIN_getOutputValue(Board_PIN_LED1));

       }

       else

       {

           /* Toggle LED1 and LED2 to indicate error */

    //                    PIN_setOutputValue(pinHandle, Board_PIN_LED1,!PIN_getOutputValue(Board_PIN_LED1));

    //                    PIN_setOutputValue(pinHandle, Board_PIN_LED2,!PIN_getOutputValue(Board_PIN_LED2));

       }

       // Prevent button reset overload

       if (optosonde_data->reason == optosonde_reason_button) {

           Task_sleep(1000000 / Clock_tickPeriod);

       }

       // Tell RTC to sleep

    #ifdef OPTOSONDE_DEMO_MODE

       uint32_t sleep_time_s = 30;

    #elif OPTOSONDE_VITICODE

       uint32_t sleep_time_s = 10 * 60;

    #else

       uint32_t sleep_time_s = 1 * 60;

    #endif

       sleepAndReset(sleep_time_s);

    }

    void *mainThread(void *arga)

    {

       I2C_Handle      i2cHandle;

       I2C_Params      i2cParams;

       int             retc;

       pthread_t alertTask;

       pthread_attr_t       pAttrs;

       sampleTime = SAMPLE_TIME;

       TMP116_Params  tmp116Params;

       /* Call driver init functions */

       //GPIO_init();

       I2C_init();

       TMP116_init();

       /* Create I2C for usage */

       I2C_Params_init(&i2cParams);

       i2cParams.bitRate = I2C_400kHz;

       i2cHandle = I2C_open(Board_I2C_TMP, &i2cParams);

       if (i2cHandle == NULL) {

           while (1);

       }

       else {

       }

       if(0 != sem_init(&tmp116Sem,0,0))

       {

           /* sem_init() failed */

           while (1);

       }

       pthread_attr_init(&pAttrs);

       pthread_attr_setstacksize(&pAttrs, TMP_TASK_STACK_SIZE);

       retc = pthread_create(&alertTask, &pAttrs, tmp116AlertTask, NULL);

       if (retc != 0) {

           /* pthread_create() failed */

           while (1);

       }

       /* Initialize tmp116Params structure to defaults */

       TMP116_Params_init(&tmp116Params);

       /* Callback for ALERT event */

       tmp116Params.callback = &tmp116Callback;

       /* Open TMP116 sensor with custom Params */

       tmp116Handle = TMP116_open(Board_TMP007_ROOMTEMP, i2cHandle, &tmp116Params);

       /* Check if the open is successful */

       if (tmp116Handle == NULL) {

          while(1);

       }

       /* Allow the sensor hardware to complete its first conversion */

       sleep(2);

       /* Get Die Temperature in Celsius */

       if (!TMP116_getTemp(tmp116Handle, TMP116_CELSIUS, &temp)) {

           //Display_print0(display, 0, 0, "TMP116 sensor read failed");

       }

       /* Begin infinite task loop */

       while (1) {

           if(0==sem_wait(&datatmp)){

               }

           if (!TMP116_getTemp(tmp116Handle, TMP116_CELSIUS, &temp)) {

           }

               datatosend =(uint16_t)(temp *100);

               sem_post(&datatmp);

            sleep(sampleTime);

       }

    }

    void maini2C(void)

    {

      pthread_t           thread;

      pthread_attr_t      pAttrs;

      struct sched_param  priParam;

      int                 retc;

      int                 detachState;

       /* Call driver init functions */

       /* Set priority and stack size attributes */

       pthread_attr_init(&pAttrs);

       priParam.sched_priority = 1;

       detachState = PTHREAD_CREATE_DETACHED;

       retc = pthread_attr_setdetachstate(&pAttrs, detachState);

       if (retc != 0) {

           /* pthread_attr_setdetachstate() failed */

          while (1);

       }

       pthread_attr_setschedparam(&pAttrs, &priParam);

      retc |= pthread_attr_setstacksize(&pAttrs, THREADSTACKSIZE);

      if (retc != 0) {

           /* pthread_attr_setstacksize() failed */

          while (1);

       }

      retc = pthread_create(&thread, &pAttrs, mainThread, NULL);

      if (retc != 0) {

           /* pthread_create() failed */

          while (1);

       }

       /* destroy pthread attribute */    

       pthread_attr_destroy(&pAttrs);

       BIOS_start();

    }

    void sendorTask_AlertCB()

    {

       static opto_sonde_data_t optosonde_data;

         /* Clear the ALERT interrupt source */

       scifClearAlertIntSource();

       if (scifGetAlertEvents() & (1 << SCIF_ADCMEAS_TASK_ID)){

           optosonde_data.reason = optosonde_reason_periodic;

           if(0!=sem_wait(&datatmp)){

           }

           optosonde_data.temp_deg_frac_8 = (int16_t)(temp *100);

           sem_post(&datatmp);

           while (!AONBatMonNewBatteryMeasureReady())

           {

               // Wait

               Task_sleep(100 * 100 / Clock_tickPeriod);

           }

           optosonde_data.bat_20mV = (AONBatMonBatteryVoltageGet() * 390625) / 2000000;

           AONBatMonDisable();

           if (PIN_getInputValue(IOID_8) == 0) {

               optosonde_data.reason = optosonde_reason_button;

           }

           // Init Tx task

           Task_Params_init(&txTaskParams);

           txTaskParams.stackSize = RFEASYLINKTX_TASK_STACK_SIZE;

           txTaskParams.priority = RFEASYLINKTX_TASK_PRIORITY + 1;

           txTaskParams.stack = &txTaskStack;

           txTaskParams.arg0 = (xdc_UArg) &optosonde_data;

           Task_construct(&txTask, rfEasyLinkTxFnx, &txTaskParams, NULL);

           }

       else

       {

           // Sensor failed

           sleepAndReset(10 * 60);

       }

       /* Acknowledge the alert event */

       scifAckAlertEvents();

       scifUninit();

    }

    void sensorTask_fn(UArg arg0, UArg arg1)

    {

       AONBatMonEnable();

       scifOsalInit();

       scifOsalRegisterTaskAlertCallback(sendorTask_AlertCB);

       scifInit(&scifDriverSetup);

       scifExecuteTasksOnceNbl(1 << SCIF_ADCMEAS_TASK_ID);

    }

    void pinInt(PIN_Handle handle, PIN_Id pinId) {

       if (pinId == 8) {

           // Force reset to trigger measure and TX

           SysCtrlSystemReset();

       }

    }

    /*

    *  ======== main ========

    */

    int opto_main(void)

    {

       /* Call driver init functions. */

       //datatemp.Data=0.0;

      // datatemp.acces=true;

       Board_initGeneral();

       pin_handle = PIN_open(&pinState, pinTable);

       PIN_registerIntCb(pin_handle, pinInt);

       if(0!=sem_init(&datatmp,0,0)){

           while(1);

       }

       // Sensor task

       Task_Params_init(&sensorTaskParams);

       txTaskParams.stackSize = RFEASYLINKTX_TASK_STACK_SIZE;

       txTaskParams.priority = RFEASYLINKTX_TASK_PRIORITY;

       txTaskParams.stack = &sensorTaskStack;

       txTaskParams.arg0 = 0;

       txTaskParams.arg1 = 0;

       Task_construct(&sensorTask, sensorTask_fn, &sensorTaskParams, NULL);

       maini2C();

       /* Start BIOS */

       return (0);

    }

  • Can you give mode details on what you mean by "having trouble accessing variable temp"? Are you having trouble converting it to int16_t from float?
    Regards,
    Prashanth
  • ProbeI2C07052018S.zipThank you for your reply,

    I am able to read the value of the temperature in the register as shown in the following figure, but when sending this value via the RF it does not work.

    here is the temp in the RF part:

    optosonde_data.temp_deg_frac_8 = (int16_t) (temp * 100)

    the value of the temperature can not be sent by the RF, while the other parameters are sent without any problem like the address mac, the state of the battrie, the address of destination.

    knowing that both RF parts and sensors work well, individually on my custom PCB, (CC1310, 4x4mm, interfaced with TMP 116 with i2c).

    thank you for taking your time to see the code to find the solution to my problem, please.

  • Hello Abdelkader,

    I see that you are using the data from a static variable in sendorTask_AlertCB() passed as a task parameter argument. Can you set a break point in the rfEasyLinkTxFnx where txpacket.payload is getting copied and check if optosonde_data->temp_deg_frac_8 indeed contains the right data. I am a bit skeptical about the static declaration of optosonde_data in sendorTask_AlertCB whose its scope is limited to that function. I am not sure passing that address of limited scoped variable to the rfEasyLinkTxFnx() would retain the values intact. Please let us know. As a work around, may be you can declare optosonde_data as a global and try first.

    Regards,
    Prashanth
  • Hello, thank you for your reply,

    i am declared optosonde_data as a global variable

    here is the result of the debug :

    Also my question is that the variable temp is protected in the context by the threads?

  • Hello, i think temp_deg_frac_8=0
    Thank you for your repley
  • What do you see in " optosonde_data.temp_deg_frac_8" after you execute this line?

    optosonde_data.temp_deg_frac_8 = (int16_t)(temp *100);

    what is the value of temp and what is the value of optosonde_data.temp_deg_frac_8
  • Thank you for your support,

    the value of optosonde_data.temp_deg_frac_8 = 0

    The value of temp is 24.666    

  • This is my code :

    /*
    * Copyright (c) 2015-2016, Texas Instruments Incorporated
    * All rights reserved.
    *
    * Redistribution and use in source and binary forms, with or without
    * modification, are permitted provided that the following conditions
    * are met:
    *
    * * Redistributions of source code must retain the above copyright
    * notice, this list of conditions and the following disclaimer.
    *
    * * Redistributions in binary form must reproduce the above copyright
    * notice, this list of conditions and the following disclaimer in the
    * documentation and/or other materials provided with the distribution.
    *
    * * Neither the name of Texas Instruments Incorporated nor the names of
    * its contributors may be used to endorse or promote products derived
    * from this software without specific prior written permission.
    *
    * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
    * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
    * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
    * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
    * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
    * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
    * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
    * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
    * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
    * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
    * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    */

    /*
    * ======== rfEasyLinkTx.c ========
    */
    /* XDCtools Header files */

    /* POSIX Header files */
    #include <pthread.h>
    #include <stdlib.h>
    #include <xdc/std.h>
    #include <xdc/runtime/System.h>
    #include <xdc/runtime/Error.h>
    #include <stdint.h>
    #include <stddef.h>
    #include <unistd.h>
    #include <semaphore.h>


    /* BIOS Header files */
    #include <ti/drivers/rf/RF.h>
    #include <ti/sysbios/BIOS.h>
    #include <ti/sysbios/knl/Task.h>
    #include <ti/sysbios/knl/Clock.h>
    #include <ti/drivers/GPIO.h>
    #include <ti/drivers/I2C.h>


    /* TI-RTOS Header files */
    #include <ti/drivers/PIN.h>
    #include <ti/drivers/Power.h>

    #include <ti/devices/cc13x0/driverlib/aon_batmon.h>
    #include <ti/devices/cc13x0/driverlib/aux_adc.h>
    #include <ti/devices/cc13x0/driverlib/chipinfo.h>
    #include <ti/devices/cc13x0/driverlib/sys_ctrl.h>
    #include <semaphore.h>
    #include <ti/sail/tmp116/tmp116.h>

    /* Board Header files */
    #include "Board.h"

    /* EasyLink API Header files */
    #include "easylink/EasyLink.h"

    #include "sc/scif.h"

    #include "version.h"
    #include "../sonde_gw_fw/sys_intf.h"

    #include <string.h>
    #include <math.h>

    #define RFEASYLINKTX_TASK_STACK_SIZE 1024
    #define RFEASYLINKTX_TASK_PRIORITY 2

    #define RFEASYLINKTX_BURST_SIZE 1
    #define THREADSTACKSIZE 768

    #define SAMPLE_TIME 1 /*In seconds*/

    #define TMP_TASK_STACK_SIZE 768

    TMP116_Handle tmp116Handle = NULL;
    I2C_Handle i2cHandle = NULL;

    sem_t tmp116Sem;

    /* Global values which may be accessed from GUI Composer App */
    float temp;

    /* Global sample rate which may be accessed and set from GUI Composer App */
    volatile uint16_t sampleTime;

    /*
    * ======== tmp116Callback ========
    * When an ALERTing condition is met on the TMP116 hardware, the ALERT pin
    * is asserted generating an interrupt. This callback function serves as
    * an ISR for a single TMP116 sensor.
    */
    void tmp116Callback(uint_least8_t index)
    {
    sem_post(&tmp116Sem);
    }

    /*
    * ======== tmp116AlertTask ========
    * This task is unblocked when the ALERT pin is asserted and generates an
    * interrupt. When the TMP116 is in INTERRUPT mode, the status register must
    * be read to clear the ALERT pin.
    */

    void *tmp116AlertTask(void *arg0)
    {
    uint16_t data;

    while(1) {

    /* Pend on semaphore, tmp116Sem */
    if (0 == sem_wait(&tmp116Sem)) {

    /* Reads status register, resetting the ALERT pin */
    TMP116_readStatus(tmp116Handle, &data);

    /* Check Object Temperature High Flag */
    if (data & TMP116_STAT_ALR_HI) {
    }

    /* Check Object Temperature Low Flag */
    if (data & TMP116_STAT_ALR_LO) {
    }

    }
    }
    }

    /* Stack size in bytes */
    //#define THREADSTACKSIZE 768

    Task_Struct txTask; /* not static so you can see in ROV */
    static Task_Params txTaskParams;
    static uint8_t txTaskStack[RFEASYLINKTX_TASK_STACK_SIZE];

    Task_Struct sensorTask; /* not static so you can see in ROV */
    static Task_Params sensorTaskParams;
    static uint8_t sensorTaskStack[RFEASYLINKTX_TASK_STACK_SIZE];


    static PIN_State pinState;
    static PIN_Handle pin_handle;


    typedef struct {
    uint8_t reason;
    int16_t temp_deg_frac_8;
    uint8_t bat_20mV;
    } opto_sonde_data_t;

    static opto_sonde_data_t optosonde_data;

    PIN_Config pinTable[] = {
    PIN_ID(8) | PIN_INPUT_EN | PIN_PULLUP | PIN_HYSTERESIS,
    PIN_TERMINATE
    };


    void sleepAndReset(uint32_t sleep_time_secs) {

    // Enable button interrupt wake up
    PIN_setInterrupt(pin_handle, PIN_ID(8) | PIN_IRQ_NEGEDGE);

    uint32_t secs = sleep_time_secs;
    while (secs > 0)
    {
    uint32_t sleep_s = secs > 2000 ? 2000 : secs;
    Task_sleep((sleep_s * 1000u * 1000) / Clock_tickPeriod);
    secs -= sleep_s;
    }

    SysCtrlSystemReset();
    }


    static void rfEasyLinkTxFnx(UArg arg0, UArg arg1)
    {

    opto_sonde_data_t* optosonde_data = (opto_sonde_data_t*) arg0;

    EasyLink_init(EasyLink_Phy_Custom);

    /*
    * If you wish to use a frequency other than the default, use
    * the following API:
    * EasyLink_setFrequency(868000000);
    */

    /* Set output power to 12dBm */
    // EasyLink_setRfPwr(12);
    EasyLink_setRfPwr(10);

    EasyLink_TxPacket txPacket;

    // Fill packet data
    uint8_t payload_ptr = 0;
    // Payload version
    txPacket.payload[payload_ptr++] = (uint8_t) (0x0);
    // Src MAC
    EasyLink_getIeeeAddr(&txPacket.payload[payload_ptr]);
    payload_ptr += 8;

    // Copy data
    txPacket.payload[payload_ptr++] = (uint8_t) (optosonde_data->reason);
    txPacket.payload[payload_ptr++] = (uint8_t) (optosonde_data->temp_deg_frac_8 >> 8);
    txPacket.payload[payload_ptr++] = (uint8_t) (optosonde_data->temp_deg_frac_8);

    txPacket.payload[payload_ptr++] = (uint8_t) (optosonde_data->bat_20mV);

    // Firmware version
    memcpy(&txPacket.payload[payload_ptr], &VERSION_HASH, sizeof(VERSION_HASH));
    payload_ptr += sizeof(VERSION_HASH);

    txPacket.len = payload_ptr;
    txPacket.absTime = 0;
    txPacket.dstAddr[0] = OPTOSONDE_ADDR;

    EasyLink_Status result = EasyLink_transmit(&txPacket);

    if (result == EasyLink_Status_Success)
    {
    /* Toggle LED1 to indicate TX */
    // PIN_setOutputValue(pinHandle, Board_PIN_LED1,!PIN_getOutputValue(Board_PIN_LED1));
    }
    else
    {
    /* Toggle LED1 and LED2 to indicate error */
    // PIN_setOutputValue(pinHandle, Board_PIN_LED1,!PIN_getOutputValue(Board_PIN_LED1));
    // PIN_setOutputValue(pinHandle, Board_PIN_LED2,!PIN_getOutputValue(Board_PIN_LED2));
    }

    // Prevent button reset overload
    if (optosonde_data->reason == optosonde_reason_button) {
    Task_sleep(1000000 / Clock_tickPeriod);
    }

    // Tell RTC to sleep
    #ifdef OPTOSONDE_DEMO_MODE
    uint32_t sleep_time_s = 30;
    #elif OPTOSONDE_VITICODE
    uint32_t sleep_time_s = 10 * 60;
    #else
    uint32_t sleep_time_s = 1 * 60;
    #endif

    sleepAndReset(sleep_time_s);
    }

    void sendorTask_AlertCB()
    {


    /* Clear the ALERT interrupt source */
    scifClearAlertIntSource();

    /* Only handle the periodic event alert */
    if (scifGetAlertEvents() & (1 << SCIF_ADCMEAS_TASK_ID))
    {
    optosonde_data.reason = optosonde_reason_periodic;


    optosonde_data.temp_deg_frac_8 =(int16_t) temp*100;


    while (!AONBatMonNewBatteryMeasureReady())
    {
    // Wait
    Task_sleep(100 * 100 / Clock_tickPeriod);
    }
    optosonde_data.bat_20mV = (AONBatMonBatteryVoltageGet() * 390625) / 2000000;
    AONBatMonDisable();

    if (PIN_getInputValue(IOID_8) == 0) {
    optosonde_data.reason = optosonde_reason_button;
    }

    // Init Tx task
    Task_Params_init(&txTaskParams);
    txTaskParams.stackSize = RFEASYLINKTX_TASK_STACK_SIZE;
    txTaskParams.priority = RFEASYLINKTX_TASK_PRIORITY + 1;
    txTaskParams.stack = &txTaskStack;
    txTaskParams.arg0 = (xdc_UArg) &optosonde_data;

    Task_construct(&txTask, rfEasyLinkTxFnx, &txTaskParams, NULL);

    }
    else
    {
    // Sensor failed
    sleepAndReset(10 * 60);
    }

    /* Acknowledge the alert event */
    scifAckAlertEvents();
    scifUninit();
    }

    void sensorTask_fn(UArg arg0, UArg arg1)
    {
    AONBatMonEnable();

    scifOsalInit();
    scifOsalRegisterTaskAlertCallback(sendorTask_AlertCB);
    scifInit(&scifDriverSetup);
    scifExecuteTasksOnceNbl(1 << SCIF_ADCMEAS_TASK_ID);
    }

    void pinInt(PIN_Handle handle, PIN_Id pinId) {
    if (pinId == 8) {
    // Force reset to trigger measure and TX
    SysCtrlSystemReset();
    }
    }



    /*
    * ======== mainThread ========
    */
    void *mainThread(void *arg0)
    {
    I2C_Handle i2cHandle;
    I2C_Params i2cParams;
    int retc;
    pthread_t alertTask;
    pthread_attr_t pAttrs;
    sampleTime = SAMPLE_TIME;

    TMP116_Params tmp116Params;

    /* Call driver init functions */
    //GPIO_init();
    I2C_init();
    TMP116_init();


    /* Create I2C for usage */
    I2C_Params_init(&i2cParams);

    i2cParams.bitRate = I2C_400kHz;

    i2cHandle = I2C_open(Board_I2C_TMP, &i2cParams);
    if (i2cHandle == NULL) {
    while (1);
    }
    else {
    }

    if(0 != sem_init(&tmp116Sem,0,0))
    {
    /* sem_init() failed */
    while (1);
    }

    pthread_attr_init(&pAttrs);
    pthread_attr_setstacksize(&pAttrs, TMP_TASK_STACK_SIZE);
    retc = pthread_create(&alertTask, &pAttrs, tmp116AlertTask, NULL);
    if (retc != 0) {
    /* pthread_create() failed */
    while (1);
    }

    /* Initialize tmp116Params structure to defaults */
    TMP116_Params_init(&tmp116Params);

    /* Callback for ALERT event */
    tmp116Params.callback = &tmp116Callback;

    /* Open TMP116 sensor with custom Params */
    tmp116Handle = TMP116_open(Board_TMP007_ROOMTEMP, i2cHandle, &tmp116Params);

    /* Check if the open is successful */
    if (tmp116Handle == NULL) {
    while(1);
    }

    /* Allow the sensor hardware to complete its first conversion */
    sleep(2);


    /* Get Die Temperature in Celsius */
    if (!TMP116_getTemp(tmp116Handle, TMP116_CELSIUS, &temp)) {

    }

    /* Begin infinite task loop */
    while (1) {

    /* Get Die and Object Temperatures */
    if (!TMP116_getTemp(tmp116Handle, TMP116_CELSIUS, &temp)) {


    }

    sleep(sampleTime);
    }
    }

    /*
    * ======== main ========
    */

    void maini2c(void)
    {
    pthread_t thread;
    pthread_attr_t pAttrs;
    struct sched_param priParam;
    int retc;
    int detachState;

    /* Call driver init functions */
    Board_initGeneral();

    /* Set priority and stack size attributes */
    pthread_attr_init(&pAttrs);
    priParam.sched_priority = 1;

    detachState = PTHREAD_CREATE_DETACHED;
    retc = pthread_attr_setdetachstate(&pAttrs, detachState);
    if (retc != 0) {
    /* pthread_attr_setdetachstate() failed */
    while (1);
    }

    pthread_attr_setschedparam(&pAttrs, &priParam);

    retc |= pthread_attr_setstacksize(&pAttrs, THREADSTACKSIZE);
    if (retc != 0) {
    /* pthread_attr_setstacksize() failed */
    while (1);
    }

    retc = pthread_create(&thread, &pAttrs, mainThread, NULL);
    if (retc != 0) {
    /* pthread_create() failed */
    while (1);
    }

    /* destroy pthread attribute */
    pthread_attr_destroy(&pAttrs);

    //return (0);
    }



    int opto_main(void)
    {

    /* Call driver init functions. */

    Board_initGeneral();
    maini2c();

    pin_handle = PIN_open(&pinState, pinTable);
    PIN_registerIntCb(pin_handle, pinInt);
    // Sensor task
    Task_Params_init(&sensorTaskParams);
    txTaskParams.stackSize = RFEASYLINKTX_TASK_STACK_SIZE;
    txTaskParams.priority = RFEASYLINKTX_TASK_PRIORITY;
    txTaskParams.stack = &sensorTaskStack;
    txTaskParams.arg0 = 0;
    txTaskParams.arg1 = 0;

    Task_construct(&sensorTask, sensorTask_fn, &sensorTaskParams, NULL);

    /* Start BIOS */
    BIOS_start();

    return (0);
    }
  • Hello Abdelkader,
    Were you able to resolve this issue? What did you find?
    Regards,
    Prashanth