Tool/software: TI-RTOS
Hello, I used C1310 LP to get the BH1750 sensor data which is a light sensor.
I successfully got the data when using the SCE "I2C Light Sensor" example.
And here is the code in SCE below:
// Select the result register i2cStart(); i2cTx(I2C_OP_WRITE | ALS_I2C_ADDR); i2cTx(0x20); // If successful ... if (state.i2cStatus == 0x0000) { U16 resultRegH; U16 resultRegL; // Read the result i2cRepeatedStart(); i2cTx(I2C_OP_READ | ALS_I2C_ADDR); i2cRxAck(resultRegH); i2cRxNack(resultRegL); i2cStop(); output.value = (resultRegH<<8) | (resultRegL); } else { i2cStop(); }
I just change my sensor slave ADDR to "0x46" and reading address to "0x20" , and then it works.
But in the "i2ctmp007.c" Example, I also change that two address, it doesn't work.
Here is the code in CCS:
void *mainThread(void *arg0) { unsigned int i; uint16_t temperature; uint8_t txBuffer[1]; uint8_t rxBuffer[2]; I2C_Handle i2c; I2C_Params i2cParams; I2C_Transaction i2cTransaction; /* Call driver init functions */ ... I2C_init(); ... /* 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] = 0x20;//TMP007_OBJ_TEMP; i2cTransaction.slaveAddress = 0x46; i2cTransaction.writeBuf = txBuffer; i2cTransaction.writeCount = 1; i2cTransaction.readBuf = rxBuffer; i2cTransaction.readCount = 2; /* Take 20 samples and print them out onto the console */ for (i = 0; i < 20; i++) { if (I2C_transfer(i2c, &i2cTransaction)) { ... 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"); return (NULL); }
It always printing out "I2C Bus fault",can everyone can help me ?