Skip to main content

Image result for BOOSTXL-SENSORS BoosterPack

Experiment to CC2640R2 and Sensor Booster Pack

In this example, I follow a tutorial from TI to read sensor OTP3001.
http://dev.ti.com/tirex/content/simplelink_academy_cc2640r2sdk_1_13_02_07/modules/ble_02_thermostat/ble_02_thermostat.html

Because the sensor TMP0007 has out of date now, so I little modify to use with OTP3001.

Step1. Copy file i2ctmp from simpllink sdk  cc2640R2 version

Reference The Booster pack datasheet http://www.ti.com/lit/ug/slau666b/slau666b.pdf

TMP0007 and OTP3001 share the I2C bus including SCL, SDA. 

Address's  TMP is 0x04, Data Register: 0x00
Address's OTP is 0x47, DataRegister: 0x00 
So in the code we modify:

#define OTP3001_REG         0x0000  /* Die Temp Result Register for TMP006 */
#define OTP3001_ADDR        0x47;

According to OTP3001 datasheet, in default, a configuration register (address 0x01) in sleep mode, so if we read data out, it will be always 0.

So we need to set it on working mode for the IC as the code below:

txBuffer[0] = 0x01; // set address of Register need to access
txBuffer[1] = 0xCC; // the configuration register has two byte and this High Byte 
txBuffer[2] = 0x10;// this is low Byte

To write to the register we use the code as following:

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

 if (I2C_transfer(i2c, &i2cTransaction))
                    {
                        light = (rxBuffer[0] << 8) | (rxBuffer[1]);
                        Display_printf(display, 0, 0, "After Configuration : %d (C)",
                                        light);
                    }

Here we print the result to UART to verify it works by reading the register.
For reading level of light at Result Register, we need to know the format of it.
From the datasheet, it has E[15-12] for exponent and  N[11-0] for number:

The value is:
M = 2**E[15-12]*N[11-0]*0.01

So we use the code below to express the result:

 i2cTransaction.writeCount = 1;
    txBuffer[0] = 0x00;
    for (sample = 0; sample < 20; sample++) {
        if (I2C_transfer(i2c, &i2cTransaction)) {
           
            pow = (rxBuffer[0] >> 4) ;
            light = ((rxBuffer[0]&0x0F) << 8) | (rxBuffer[1]);
            while(pow!=0)
            {
                pow -=1;      // Multiply 2^n by left shifting to n times
                light <<=1;
            }
            light *=0.01;


            Display_printf(display, 0, 0, "Sample %u: %d (C)",
                sample, light); //temperature
        }
        else {
            Display_printf(display, 0, 0, "I2C Bus fault.");
        }

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

here we declare two variable: pow for Exponent part and light for result in decimal

And the result on UART as below:



Comments

Popular posts from this blog

Arduino Code for test Heart Rate 7 Click

Heart Rate 7 Click is the newest module from MikroE which uses VEM8080 photodetector has a wide range spectrum from 300nm - 1000nm. To control and acquisition data, AFE4404 from TI inc. is adopted. This chip permits control 3 LED channels, and sample heart rate default 100 SPS.  A 22-bit ADC permit collecting very small changed voltage from a PD sensor. In this example we config Arduino Mega  2650 as below: Pin 4 for RST PIN 5 CLK PIN 6 INT PIN 20 SDA PIN 21 SCL Config registers follow the default of AFE4404 datasheet Page 27 with some minor changes. 1. Config Internal Clock through  AFE_CONTROL2 register addr.: 0x23 value: 0x104218  // setup all dynamic power to save energy 2. Control LED2 current through AFE_LEDCNTRL register addr: 0x22 value: 0x000100 3. Read data using PROG_TG_EN signal through AFE_TIA_GAIN register addr: 0x21 value: 0x000125 Time to start and end of PROG_TG setup through two registers: AFE_PROG_TG_STC register (...
Serial Port Profile with CC2650 and CC2640R2 (part 2) Modified to transfer ADC values up to PC Step 1:  Include ACD.h library #include <ti/drivers/ADC.h>  Step 2: Insert period event in order to update ADC read values from the potentiometer #define SSSS_ICALL_EVT                         ICALL_MSG_EVENT_ID // Event_Id_31 #define SSSS_QUEUE_EVT                         UTIL_QUEUE_EVENT_ID // Event_Id_30 #define SSSS_PERIODIC_EVT                      Event_Id_00 //SOLUTION // Bitwise OR of all events to pend on #define SSSS_ALL_EVENTS                        (SSSS_ICALL_EVT        | \                                ...
Programing on Launchpad MSP432 Interrupt button Prerequisite: Hardware: Launchpad MSP432P401 IDE software: IAR/CCS/KEIL Tool: Simplelink SDK MSP432 v3.20.00.06 Description: Simple program using two buttons connected to P1.0  and P1.4 to turn on or turn off LED on P1.0 Step1. Open example of Simplelink SDK without RTOS Step2. modify the code as below Step3. Compile and debug the program /* DriverLib Includes */ #include <ti/devices/msp432p4xx/driverlib/driverlib.h> /* Standard Includes */ #include <stdint.h> #include <stdbool.h> volatile uint32_t SW1, SW2; //semaphores void VectorButtons_Init(void){   __disable_interrupt;   //DisableInterrupts();          // set the I bit during initialization   SW1 = 0; SW2 = 0;             // clear semaphores   P1->SEL0 &= ~0x12;   P1->SEL1 &= ~0x12;      P1->D...