What I want to do is get the IR temperature and the humidity sensor reading using sensortag. I know that the sensortag source code in the ble sdk contains the code. But I need to read reading from external sensor(Si7006-A20-IM). So I started with cc2650 sensortag( because tmp007 is simmiler to the sensor I need to use) and tried to extend source code for launchpad(simple_peripheral) and read temperature sensor from tmp007.
What I did is mostly editing simple_peripheral.c in Application. There is a task with call back function simpleBLEPeripheral_taskFxn() and this task is created in SimpleBLEPeripheral_createTask(). I have similarly created a task calling function create_MyTask() from main to create the task and the callback function being MyTask_fxn(). I have posted a semaphore associated with MyTask in seimpleBLEPeripheral_taskFxn() so that bios may run MyTask. The task runs fine.
Next I copy pasted the I2C codes from example i2ctmp007_CC2650STK_TI_CC2650f128(runs fine on sensortag) into the MyTask function.
unsigned int i;
uint16_t temperature;
uint8_t txBuffer[1];
uint8_t rxBuffer[2];
I2C_Handle i2c;
I2C_Params i2cParams;
I2C_Transaction i2cTransaction;
/* Create I2C for usage */
I2C_Params_init(&i2cParams);
i2cParams.bitRate = I2C_400kHz;
i2c = I2C_open(0, &i2cParams);
if (i2c == NULL) {
msg[7]='n';
//System_abort("Error Initializing I2C\n");
}
else {
//msg[7]=I2C_transfer(i2c, &i2cTransaction);
//System_printf("I2C Initialized!\n");
}
/* Point to the T ambient register and read its 2 bytes */
txBuffer[0] = TMP007_OBJ_TEMP;
i2cTransaction.slaveAddress = Board_TMP007_ADDR;
i2cTransaction.writeBuf = txBuffer;
i2cTransaction.writeCount = 1;
i2cTransaction.readBuf = rxBuffer;
i2cTransaction.readCount = 2;
msg[9] ++;
if (I2C_transfer(i2c, &i2cTransaction)) {
temp = 16;
/* Extract degrees C from the received data; see TMP102 datasheet */
temperature = (rxBuffer[0] << 6) | (rxBuffer[1] >> 2);
/*
* If the MSB is set '1', then we have a 2's complement
* negative value which needs to be sign extended
*/
if (rxBuffer[0] & 0x80) {
temperature |= 0xF000;
}
/*
* For simplicity, divide the temperature value by 32 to get rid of
* the decimal precision; see TI's TMP007 datasheet
*/
temperature /= 32;
msg[5]= temperature;
temp = 12;
//System_printf("Sample %u: %d (C)\n", i, temperature);
}
else {
// System_printf("I2C Bus fault\n");
}
I2C_open(0, &i2cParams) does not return false. But I2C_transfer(i2c, &i2cTransaction) does not work. codes in if condition never executes.