Part Number: CC2640R2F
Other Parts Discussed in Thread: TMP1075
Tool/software: Code Composer Studio
Hi,
I am using I2C example code for TMP1075.
For I2C is working properly or not I am just reading the device ID of the sensor.
I am using the following way but I am not getting the correct device Id.
Can anyone please help me with this?
#include <stdint.h>
#include <stddef.h>
#include <unistd.h>
/* Driver Header files */
#include <ti/drivers/GPIO.h>
#include <ti/drivers/I2C.h>
#include <ti/display/Display.h>
/* Example/Board Header files */
#include "Board.h"
#define TASKSTACKSIZE 640
#define TMP1075_ADDR 0x48
#define DEVICE_ID_REG 0x0F /* Device IDRegister */
#ifndef Board_TMP_ADDR
#define Board_TMP_ADDR TMP1075_ADDR
#endif
static Display_Handle display;
/*
* ======== mainThread ========
*/
void *mainThread(void *arg0)
{
uint8_t txBuffer[8];
uint8_t rxBuffer[8];
I2C_Handle i2c;
static I2C_Params i2cParams;
/* Call driver init functions */
Display_init();
/* Open the HOST display for output */
display = Display_open(Display_Type_UART, NULL);
if (display == NULL) {
while (1);
}
I2C_init();
/* Create I2C for usage */
I2C_Params_init(&i2cParams);
i2cParams.bitRate = I2C_100kHz;
i2cParams.transferMode = I2C_MODE_BLOCKING;
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");
}
txBuffer[0] = DEVICE_ID_REG;
i2cTransaction.slaveAddress = Board_TMP_ADDR;
i2cTransaction.writeBuf = txBuffer;
i2cTransaction.readBuf = rxBuffer;
i2cTransaction.writeCount = 1;
i2cTransaction.readCount = 2;
for(;;)
{
I2C_transfer(i2c,&i2cTransaction);
Display_printf(display, 0, 0,"Device ID: %x %x",rxBuffer[0],rxBuffer[1]);
sleep(1);
}
}