Experiment Sensor Booster Pack with CC2650
In this experiment, we use CC2650 rather CC2640Rx2 to read light level from OTP3001 on the sensor board. It follows the Task 3, Task 4 from TI tutorial
http://dev.ti.com/tirex/content/simplelink_academy_cc2640r2sdk_1_13_02_07/modules/ble_02_thermostat/ble_02_thermostat.html
Here we need some modified like last post to make the project run.
First, to define the board CC2650 in file Board.h
#define Board_I2C_TMP CC2650_LAUNCHXL_I2C0
Also, define IC address in file otp3001.c( replaced for tmp007.c)
#define Board_TMP_ADDR 0x47
#if defined(ONBOARD_TMP006)
#define TMP_REGISTER TMP_DIE_TEMP
#define TMP_ADDR Board_TMP_ADDR
#else
#define TMP_REGISTER TMP_OBJ_TEMP
#define CONF_REGISTER 0x01
#define TMP_ADDR Board_TMP_ADDR
#endif
Declare two new variables for reading exponent part and result
uint16_t light;
uint8_t pow;
//uint32_t temperature;
//float temperatureC;
//float temperatureF;
Again, as the last post, we change the procedure to change content of configuration register and method to compute light level as its described datasheet
static void tmp007TaskFxn(UArg a0, UArg a1)
{
uint8_t txBuffer[3];
uint8_t rxBuffer[2];
I2C_Handle i2c;
I2C_Params i2cParams;
I2C_Transaction i2cTransaction;
UInt key;
I2C_init();
/* Create I2C for usage */
I2C_Params_init(&i2cParams);
i2cParams.bitRate = I2C_400kHz;
i2c = I2C_open(Board_I2C_TMP, &i2cParams);
if (i2c == NULL) {
System_abort("***ERROR*** >> FAILED TO OPEN I2C PORT");
}
Error_init(&eb);
/* Default instance configuration params */
readEvent = Event_create(NULL, &eb);
if (readEvent == NULL) {
System_abort("***ERROR*** >> EVENT CREATE FAILED");
}
/*
* The Sensors Boosterpack contains a TMP007 where you can get
* TMP_DIE_TEMP or TMP_OBJ_TEMP.
* Note: no calibration is being done on the TMP00x device to simplify
* the example code.
*/
txBuffer[0] = TMP_REGISTER;
i2cTransaction.slaveAddress = TMP_ADDR;
i2cTransaction.writeBuf = txBuffer;
i2cTransaction.readBuf = rxBuffer;
i2cTransaction.readCount = 2;
//Config OTP3001
txBuffer[0] = CONF_REGISTER;
txBuffer[1] = 0xCC;
txBuffer[2] = 0x10;
i2cTransaction.writeCount = 3;
if (I2C_transfer(i2c, &i2cTransaction))
{
light = (rxBuffer[0] << 8) | (rxBuffer[1]);
Log_info1("After Configuration : %d (C)",(IArg)light);
}
//After config, read Register address: 0x00
txBuffer[0] = TMP_REGISTER;
i2cTransaction.writeCount = 1;
while (1) {
Event_pend(readEvent, Event_Id_NONE, Event_Id_00, BIOS_WAIT_FOREVER);
if (I2C_transfer(i2c, &i2cTransaction)) {
/*
* Extract degrees C from the received data; see sensor datasheet.
*/
key = Hwi_disable();
//temperature = (rxBuffer[0] << 6) | (rxBuffer[1] >> 2);
//temperatureC = temperature * 0.03125;
//temperatureF = temperatureC * 9 / 5 + 32;
pow = (rxBuffer[0] >> 4) ;
light = ((rxBuffer[0]&0x0F) << 8) | (rxBuffer[1]);
while(pow!=0)
{
pow -=1;
light <<=1;
}
light *=0.01;
Hwi_restore(key);
}
MyLight_SetParameter(MYLIGHT_MYLIGHTDATA, MYLIGHT_MYLIGHTDATA_LEN, &light);
//Log_info1("I2C RX BUF: 0x%x", (IArg)temperature);
//temperature = (((temperature&0xff) << 24)|((temperature&0xff00)<<8)|((temperature&0xff0000)>>8)|((temperature&0xff000000) >> 24));
//Log_info1("Sent over BLE: 0x%x", (IArg)light);
Log_info1("Light level: %d", (IArg)light);
//Log_info1("Temperature Farenheit: %d", (IArg)temperatureF);
}
}
If you compiled at this point, the program will make error for the name:
Board_I2C_TMP so we need define it in Board.h
#define Board_I2C_TMP CC2650_LAUNCHXL_I2C0
The measurement result can be read from UART or App Bluetooth (Light Blue/SensorTag)
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiWFIlXIZXU1ztzelTDM6StMDB58MJXPnCIMVWKbpzkd215O-96q7-0Ar8J14O2DED8vvEkutXZuf0rfqtgWeGnhYEQTsAx0ak_7smrc2q41b76FjqkzWpQQGnYL8Hab0loOoAnqHlJuVI/s320/Image-1.jpg)
In this experiment, we use CC2650 rather CC2640Rx2 to read light level from OTP3001 on the sensor board. It follows the Task 3, Task 4 from TI tutorial
http://dev.ti.com/tirex/content/simplelink_academy_cc2640r2sdk_1_13_02_07/modules/ble_02_thermostat/ble_02_thermostat.html
Here we need some modified like last post to make the project run.
First, to define the board CC2650 in file Board.h
#define Board_I2C_TMP CC2650_LAUNCHXL_I2C0
Also, define IC address in file otp3001.c( replaced for tmp007.c)
#define Board_TMP_ADDR 0x47
#if defined(ONBOARD_TMP006)
#define TMP_REGISTER TMP_DIE_TEMP
#define TMP_ADDR Board_TMP_ADDR
#else
#define TMP_REGISTER TMP_OBJ_TEMP
#define CONF_REGISTER 0x01
#define TMP_ADDR Board_TMP_ADDR
#endif
Declare two new variables for reading exponent part and result
uint16_t light;
uint8_t pow;
//uint32_t temperature;
//float temperatureC;
//float temperatureF;
Again, as the last post, we change the procedure to change content of configuration register and method to compute light level as its described datasheet
static void tmp007TaskFxn(UArg a0, UArg a1)
{
uint8_t txBuffer[3];
uint8_t rxBuffer[2];
I2C_Handle i2c;
I2C_Params i2cParams;
I2C_Transaction i2cTransaction;
UInt key;
I2C_init();
/* Create I2C for usage */
I2C_Params_init(&i2cParams);
i2cParams.bitRate = I2C_400kHz;
i2c = I2C_open(Board_I2C_TMP, &i2cParams);
if (i2c == NULL) {
System_abort("***ERROR*** >> FAILED TO OPEN I2C PORT");
}
Error_init(&eb);
/* Default instance configuration params */
readEvent = Event_create(NULL, &eb);
if (readEvent == NULL) {
System_abort("***ERROR*** >> EVENT CREATE FAILED");
}
/*
* The Sensors Boosterpack contains a TMP007 where you can get
* TMP_DIE_TEMP or TMP_OBJ_TEMP.
* Note: no calibration is being done on the TMP00x device to simplify
* the example code.
*/
txBuffer[0] = TMP_REGISTER;
i2cTransaction.slaveAddress = TMP_ADDR;
i2cTransaction.writeBuf = txBuffer;
i2cTransaction.readBuf = rxBuffer;
i2cTransaction.readCount = 2;
//Config OTP3001
txBuffer[0] = CONF_REGISTER;
txBuffer[1] = 0xCC;
txBuffer[2] = 0x10;
i2cTransaction.writeCount = 3;
if (I2C_transfer(i2c, &i2cTransaction))
{
light = (rxBuffer[0] << 8) | (rxBuffer[1]);
Log_info1("After Configuration : %d (C)",(IArg)light);
}
//After config, read Register address: 0x00
txBuffer[0] = TMP_REGISTER;
i2cTransaction.writeCount = 1;
while (1) {
Event_pend(readEvent, Event_Id_NONE, Event_Id_00, BIOS_WAIT_FOREVER);
if (I2C_transfer(i2c, &i2cTransaction)) {
/*
* Extract degrees C from the received data; see sensor datasheet.
*/
key = Hwi_disable();
//temperature = (rxBuffer[0] << 6) | (rxBuffer[1] >> 2);
//temperatureC = temperature * 0.03125;
//temperatureF = temperatureC * 9 / 5 + 32;
pow = (rxBuffer[0] >> 4) ;
light = ((rxBuffer[0]&0x0F) << 8) | (rxBuffer[1]);
while(pow!=0)
{
pow -=1;
light <<=1;
}
light *=0.01;
Hwi_restore(key);
}
MyLight_SetParameter(MYLIGHT_MYLIGHTDATA, MYLIGHT_MYLIGHTDATA_LEN, &light);
//Log_info1("I2C RX BUF: 0x%x", (IArg)temperature);
//temperature = (((temperature&0xff) << 24)|((temperature&0xff00)<<8)|((temperature&0xff0000)>>8)|((temperature&0xff000000) >> 24));
//Log_info1("Sent over BLE: 0x%x", (IArg)light);
Log_info1("Light level: %d", (IArg)light);
//Log_info1("Temperature Farenheit: %d", (IArg)temperatureF);
}
}
If you compiled at this point, the program will make error for the name:
Board_I2C_TMP so we need define it in Board.h
#define Board_I2C_TMP CC2650_LAUNCHXL_I2C0
The measurement result can be read from UART or App Bluetooth (Light Blue/SensorTag)
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiWFIlXIZXU1ztzelTDM6StMDB58MJXPnCIMVWKbpzkd215O-96q7-0Ar8J14O2DED8vvEkutXZuf0rfqtgWeGnhYEQTsAx0ak_7smrc2q41b76FjqkzWpQQGnYL8Hab0loOoAnqHlJuVI/s320/Image-1.jpg)
Comments
Post a Comment