Part Number: LAUNCHCC3220MODASF
Other Parts Discussed in Thread: TMP006
Tool/software: TI C/C++ Compiler
Hi,
I have combined the timerled and i2ctemp examples to get the temperature value on every second but it is giving me error : I2C bus fault.
I have tried to resolve the issue but I couldn't understand why is occurring, please suggest me how could I resolve this issue ?
Here is the code and screenshot of the debug page:
#include <stdio.h>
#include <stdint.h>
#include <stddef.h>
#include <unistd.h>
#include <ti/drivers/GPIO.h>
#include <ti/drivers/I2C.h>
#include <ti/display/Display.h>
#include <ti/drivers/Timer.h>
#include "Board.h"
#define TMP006_DIE_TEMP 0x0001
uint16_t temperature;
uint8_t txBuffer[1];
uint8_t rxBuffer[2];
I2C_Transaction i2cTransaction;
I2C_Handle i2c;
I2C_Params i2cParams;
int flag;
void timerCallback();
void *mainThread(void *arg0)
{
Timer_Handle timer0;
Timer_Params params;
GPIO_init();
Timer_init();
I2C_init();
I2C_Params_init(&i2cParams);
i2cParams.bitRate = I2C_400kHz;
GPIO_setConfig(Board_GPIO_LED0, GPIO_CFG_OUT_STD | GPIO_CFG_OUT_LOW);
GPIO_write(Board_GPIO_LED0, Board_GPIO_LED_OFF);
Timer_Params_init(¶ms);
params.period = 1000000;
params.periodUnits = Timer_PERIOD_US;
params.timerMode = Timer_CONTINUOUS_CALLBACK;
params.timerCallback = timerCallback;
timer0 = Timer_open(Board_TIMER0, ¶ms);
if (timer0 == NULL) {
while (1);
}
if (Timer_start(timer0) == Timer_STATUS_ERROR) {
while (1);
}
return (NULL);
}
void timerCallback()
{
i2c = I2C_open(Board_I2C_TMP, &i2cParams);
if (i2c == NULL) {
printf( "Error Initializing I2C\n");
while (1);
}
else {
printf( "I2C Initialized!\n");
}
txBuffer[0] = TMP006_DIE_TEMP;
i2cTransaction.slaveAddress = Board_TMP_ADDR;
i2cTransaction.writeBuf = txBuffer;
i2cTransaction.writeCount = 1;
i2cTransaction.readBuf = rxBuffer;
i2cTransaction.readCount = 2;
flag = I2C_transfer(i2c, &i2cTransaction);
if (flag) {
temperature = (rxBuffer[0] << 6) | (rxBuffer[1] >> 2);
if (rxBuffer[0] & 0x80) {
temperature |= 0xF000;
}
temperature /= 32;
printf( "Sample %d (C)\n", temperature);
}
else {
printf("I2C Bus fault\n");
}
I2C_close(i2c);
printf("I2C closed!\n");
}
