Tool/software: TI-RTOS
I hava a custom board as follow:
I have 2 i2c devices on this board (not sure if this causes the problem), a vl53l0x TOF sensor and a SHT21 temperature and humidity sensor, both with the same sda and scl, hooked up on dio27 and dio28 respectively.
I could make the SHT21 work, i could get the temperature, humidity readings fine, no problem.
However, i couldnt get the vl53l0x TOF sensor to work, I2C_transfer() would return false.
The following is my code snippet:
void *pirThread(void *arg0){ /* Call driver init functions */ I2C_init(); /* Create I2C for usage */ I2C_Params_init(&i2cParams); i2cParams.bitRate = I2C_400kHz; i2cParams.transferMode = I2C_MODE_BLOCKING; i2c = I2C_open(Board_I2C_TMP, &i2cParams); if (i2c == NULL) { //Error Initializing I2C while (1); } i2cTransaction.slaveAddress = 0x52; //TOF device address txBuffer[0] = 0x80; // index ? txBuffer[1] = 0x01; // data ? i2cTransaction.writeBuf = txBuffer; i2cTransaction.writeCount = 2; //number of bytes to send i2cTransaction.readBuf = rxBuffer; //memory location to save read data i2cTransaction.readCount = 2; //num of bytes to save // not working: return false if(I2C_transfer(i2c, &i2cTransaction)){ printf("write success\n"); res = rxBuffer[0]; } // the following works as expected: i2cTransaction.slaveAddress = 040; //SHT21 device address txBuffer[0] = SHT21_TEMP_CMD; //E3 i2cTransaction.writeBuf = txBuffer; i2cTransaction.writeCount = 1; //number of bytes to send i2cTransaction.readBuf = rxBuffer; //memory location to save read data i2cTransaction.readCount = 2; //num of bytes to save float tempC; while(1){ if(I2C_transfer(i2c, &i2cTransaction)){ tempC = calTemp((rxBuffer[0] << 8) | rxBuffer[1]); printf("TempC : %f\n", tempC); } } /* Deinitialized I2C */ I2C_close(i2c); }
Any help is appreciated.