Part Number: LAUNCHXL-CC1352R1
Other Parts Discussed in Thread: OPT3001, STRIKE
Tool/software: Code Composer Studio
Hi,
I have a sensors boosterpack and I want to measure the temperature with the TMP007. I have run one example but it doesn't work:
I also ran this version too and it still doesn't work:
The problem is that the board doesn't find the TMP007:
I'd apreciate some help, I'll paste the code below so you can see what I've changed in my program, I'm using Tirtos:
#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
/*
* ======== TMP Registers ========
*/
#define TMP007_DIE_TEMP 0x0001 /* Die Temp Result Register */
#define TMP007_OBJ_TEMP 0x0003 /* Object Temp Result Register */
#define TMP007_ADDR 0x40;
#ifndef Board_TMP_ADDR
#define Board_TMP_ADDR TMP007_ADDR
#endif
static Display_Handle display;
/*
* ======== mainThread ========
*/
void *mainThread(void *arg0)
{
uint16_t sample;
uint16_t temperature;
uint8_t txBuffer[1];
uint8_t rxBuffer[2];
I2C_Handle i2c;
I2C_Params i2cParams;
I2C_Transaction i2cTransaction;
/* Call driver init functions */
Display_init();
GPIO_init();
I2C_init();
/* Configure the LED and if applicable, the TMP116_EN 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 i2ctmp example.");
/* Create I2C for usage */
I2C_Params_init(&i2cParams);
i2cParams.bitRate = I2C_400kHz;
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");
}
/* Common I2C transaction setup */
i2cTransaction.writeBuf = txBuffer;
i2cTransaction.writeCount = 1;
i2cTransaction.readBuf = rxBuffer;
i2cTransaction.readCount = 2;
txBuffer[0] = 0x0003;
i2cTransaction.slaveAddress = TMP007_ADDR;
if (!I2C_transfer(i2c, &i2cTransaction)) {
Display_printf(display, 0, 0, "Error. No TMP sensor found!");
while(1);
}
/* Take 20 samples and print them out onto the console */
for (sample = 0; sample < 20; sample++) {
if (I2C_transfer(i2c, &i2cTransaction)) {
temperature = (rxBuffer[0] << 8) | (rxBuffer[1]);
temperature *= 0.0078125;
if (rxBuffer[0] & 0x80) {
temperature |= 0xF000;
}
Display_printf(display, 0, 0, "Sample %u: %d (C)",
sample, temperature);
}
else {
Display_printf(display, 0, 0, "I2C Bus fault.");
}
sleep(1);
}
I2C_close(i2c);
Display_printf(display, 0, 0, "I2C closed!");
return (NULL);
