Other Parts Discussed in Thread: TMP006, TMP102, CC3220SF
Tool/software: Code Composer Studio
Hey guys,
I am trying to interface AM2315 temperature sensor with cc3220 sf via I2C communication. The sensor works on 5V logic level and the board works on 3.3 V logic level, so I am using a level shifter between the board and the sensor. In firmware i am using I2c006tmp example:
//#define TMP006_ADDR 0x41
//#define TMP006_DIE_TEMP 0x0001 /* Die Temp Result Register */
//#ifndef Board_TMP_ADDR
//#define Board_TMP_ADDR TMP006_ADDR
//#endif
static Display_Handle display;
/*
* ======== mainThread ========
*/
void *mainThread(void *arg0)
{
unsigned int i;
uint16_t temperature;
uint16_t humidity;
uint8_t txBuffer[3];
uint8_t rxBuffer[10];
I2C_Handle i2c;
I2C_Params i2cParams;
I2C_Transaction i2cTransaction;
/* Call driver init functions */
Display_init();
GPIO_init();
I2C_init();
/* Configure the LED pin */
GPIO_setConfig(Board_GPIO_LED0, GPIO_CFG_OUT_STD | GPIO_CFG_OUT_LOW);
/* Open the HOST display for output */
display = Display_open(Display_Type_UART, NULL);
if (display == NULL) {
while (1);
}
/* Turn on user LED */
GPIO_write(Board_GPIO_LED0, Board_GPIO_LED_ON);
Display_printf(display, 0, 0, "Starting the i2ctmp006 example\n");
/* Create I2C for usage */
I2C_Params_init(&i2cParams);
i2cParams.bitRate = I2C_100kHz;
i2c = I2C_open(Board_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");
}
/* Point to the T ambient register and read its 2 bytes */
txBuffer[0] = 0x03;
txBuffer[1] = 0x00;
txBuffer[2] = 4;
i2cTransaction.slaveAddress = 0x5C;
i2cTransaction.writeBuf = txBuffer;
i2cTransaction.writeCount = 3;
i2cTransaction.readBuf = rxBuffer;
i2cTransaction.readCount = 2;
/* Take 5 samples and print them out onto the console */
for (i = 0; i < 5; i++)
{
if (I2C_transfer(i2c, &i2cTransaction))
{
/* Extract degrees C from the received data; see TMP102 datasheet */
humidity = rxBuffer[2];
humidity = humidity * 256;
humidity = humidity + rxBuffer[3];
humidity = humidity /10;
temperature = rxBuffer[4] & 0x7F;
temperature = temperature * 256;
temperature = temperature + rxBuffer[5];
temperature = temperature / 10;
if(rxBuffer[4] >> 7)
{
temperature = -temperature;
}
/*
// if (rxBuffer[0] & 0x80) {
// temperature |= 0xF000;
// }
// /*
// * For simplicity, divide the temperature value by 32 to get rid of
// * the decimal precision; see TI's TMP006 datasheet
// */
// temperature /= 32;
Display_printf(display, 0, 0, "Sample %u: %d (C)\n", i, temperature);
}
else {
Display_printf(display, 0, 0, "I2C Bus fault\n");
}
/* Sleep for 1 second */
sleep(1);
}
/* Deinitialized I2C */
I2C_close(i2c);
Display_printf(display, 0, 0, "I2C closed!\n");
}
All I am getting at the console is "I2c bus fault). Please tell me what I am doing wrong.