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.

LAUNCHCC3235MOD: Minimizing duration of call to get temperature

Part Number: LAUNCHCC3235MOD

What can I initialize elsewhere and only get temperature in

 

// main_rtos
 Board_init();
    GPIO_init();
    I2C_init();
    GPIO_setConfig(CONFIG_GPIO_LED_0, GPIO_CFG_OUT_STD | GPIO_CFG_OUT_LOW);
   #ifdef CONFIG_GPIO_TMP_EN
       GPIO_setConfig(CONFIG_GPIO_TMP_EN, GPIO_CFG_OUT_STD | GPIO_CFG_OUT_HIGH);
       /* Allow the sensor to power on */
       sleep(1);
   #endif
    /* Set priority and stack size attributes */
//...
// tcpecho.c
void static i2c0 (void){
    uint16_t sample;
        int16_t temperature;
        uint8_t txBuffer[1];
        uint8_t rxBuffer[2];
        int8_t i;
        I2C_Handle i2c;
        I2C_Params i2cParams;
        I2C_Transaction i2cTransaction;

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

        /* Configure the LED and if applicable, the TMP_EN pin */
    //    GPIO_setConfig(CONFIG_GPIO_LED_0, GPIO_CFG_OUT_STD | GPIO_CFG_OUT_LOW);
    #ifdef CONFIG_GPIO_TMP_EN
        GPIO_setConfig(CONFIG_GPIO_TMP_EN, GPIO_CFG_OUT_STD | GPIO_CFG_OUT_HIGH);
        /* Allow the sensor to power on */
        sleep(1);
    #endif


        /* Turn on user LED */
        GPIO_write(CONFIG_GPIO_LED_0, CONFIG_GPIO_LED_ON);
        Display_printf(display, 0, 0, "Starting the i2ctmp example\n");

        /* Create I2C for usage */
        I2C_Params_init(&i2cParams);
        i2cParams.bitRate = I2C_400kHz;
        i2c               = I2C_open(CONFIG_I2C_TMP, &i2cParams);
        if (i2c == NULL)
        {
            Display_printf(display, 0, 0, "Error Initializing I2C\n");
            while (1) {}
        }
        else
        {
            Display_printf(display, 0, 0, "I2C Initialized!\n");
        }

        /* Common I2C transaction setup */
        i2cTransaction.writeBuf   = txBuffer;
        i2cTransaction.writeCount = 1;
        i2cTransaction.readBuf    = rxBuffer;
        i2cTransaction.readCount  = 0;

        /*
         * Determine which I2C sensors are present by querying known I2C
         * target addresses.
         */
        for (i = TMP_COUNT - 1; i >= 0; i--)
        {
            i2cTransaction.targetAddress = sensors[i].address;
            txBuffer[0]                  = sensors[i].resultReg;

            if (I2C_transfer(i2c, &i2cTransaction))
            {
                targetAddress = sensors[i].address;
                Display_printf(display,
                               0,
                               0,
                               "Detected TMP%s sensor with target"
                               " address 0x%x",
                               sensors[i].id,
                               sensors[i].address);
            }
            else
            {
                i2cErrorHandler(&i2cTransaction, display);
            }
        }

        /* If we never assigned a target address */
        if (targetAddress == 0)
        {
            Display_printf(display, 0, 0, "Failed to detect a sensor!");
            I2C_close(i2c);
            while (1) {}
        }

        Display_printf(display, 0, 0, "\nUsing last known sensor for samples.");
        i2cTransaction.targetAddress = targetAddress;

        /* Take 3 samples and print them out onto the console */
        i2cTransaction.readCount = 2;
        for (sample = 0; sample < 3; sample++)
        {
            if (I2C_transfer(i2c, &i2cTransaction))
            {
                /*
                 * Extract degrees C from the received data;
                 * see TMP sensor datasheet
                 */
                temperature = (rxBuffer[0] << 8) | (rxBuffer[1]);
                temperature *= 0.0078125;

                Display_printf(display, 0, 0, "Sample %u: %d C", sample, temperature);
            }
            else
            {
                i2cErrorHandler(&i2cTransaction, display);
            }

            /* Sleep for 1 second */
            sleep(1);
        }

        I2C_close(i2c);
        Display_printf(display, 0, 0, "I2C closed!");




}

So many attempts with moved omissions seem to fail. And with so miny failures I seem to have perplexed router and/or local AP by using a hostname in platform.c rather than a fixed ip address. I guess that should be another question.

  • Hi Malcolm,

    I'm not sure I understand your question, do you have a failure?. It seems you have a modified the I2Ctmp example. Can you further explain what you are trying to accomplish in your application?

    Kind regards,

    Rogelio

  • I have essentially pasted the i2c example code in a function that I would like to pare down to the fastest call to get temperature, and put in a one time initialization code and closing somewhere else or in the function as a once only initialization. If all the steps are necessary, such as waiting a second to power on, then I would like to know that. In some relatively fast running code, I would not want to wait for more than a second, and would hope to use a timer and write to a circular buffer so that when the call to get latest temperature would execute quickly. I am also struggling with setting the clock by sntp(never seems to set clock), and then getting a timestamp that would go with temperature.

    The troubles with connecting seem to be with multiple, 15 to 20, connects with test program with my AP point(ruckus 7984) which get fixed after rebooting it and nothing to do with router(rv040g).

  • SNTP time working, clock set and timestamp done. I will post when cleaned up. Questions about ic2 remain.

  • Hi Malcom,

    Quickly looking over your code, I see you try to Intialize I2C twice. What I would do for the most efficient code is initialize everything (including enabling the temp sensor), and then do the I2C transaction from the Sensor to the device on a seperate thread. In regards to the 1 second sleep, Im not sure exatly how much time is needed to turn on the sensor but as long as there is no call to do a transaction from the device before it powers on, you could risk not sleeping the 1 second.

    Kind Regards,

    Rogelio