by sigfoxsignal Mon Nov 14, 2016 11:14 pm
Hello everybody,
I have been trying for several days to interface my TD1208 to a HTU21D temperature/humidity sensor using I2C.
But I cannot succeed and feel desesperate.
I2C_Transfer() function always return -1.
I have put my oscilloscope on the SCL output of the TD1208 and it seems the output is always +3.3v.
I am using two 12kOhms resistors.
Here is my code :
// Configure needed clock to have I2C working
CMU_ClockEnable(cmuClock_I2C0, true);
CMU_ClockEnable(cmuClock_GPIO, true);
// Configure I/O pins for working as I2C - Output Open Drain
GPIO_PinModeSet(SCL_PORT, SCL_BIT, gpioModeWiredAnd, 1);
GPIO_PinModeSet(SDA_PORT, SDA_BIT, gpioModeWiredAnd, 1);
I2C0->ROUTE = I2C_ROUTE_SDAPEN | I2C_ROUTE_SCLPEN | _I2C_ROUTE_LOCATION_LOC0;
// Init the I2C with default param 100KHz
I2C_Init_TypeDef i2cInit = I2C_INIT_DEFAULT;
I2C_Init(I2C0, &i2cInit);
// Prepare for the transaction
I2C_TransferSeq_TypeDef i2cTransfert;
uint8_t command[1] = {0};
uint8_t values[3] = {0,0,0};
i2cTransfert.addr = HTU21D_ADDRESS;
// Send HUMD MEASURE command to HTU21D
i2cTransfert.flags = I2C_FLAG_WRITE;
command[0] = TRIGGER_HUMD_MEASURE_NOHOLD;
i2cTransfert.buf[0].len = 1;
i2cTransfert.buf[0].data = command;
int _status = I2C_TransferInit(I2C0, &i2cTransfert);
while ( _status == i2cTransferInProgress) {
_status = I2C_Transfer(I2C0);
}
// ===> At this point _status is -1
// Get the HUMD MEASURE data from HTU21D
i2cTransfert.flags = I2C_FLAG_READ;
i2cTransfert.buf[0].len = 3;
i2cTransfert.buf[0].data = values;
_status = I2C_TransferInit(I2C0, &i2cTransfert);
while ( _status == i2cTransferInProgress) {
_status = I2C_Transfer(I2C0);
}
// ===> At this point _status is -1
Do you know what is wrong or what I am missing ?
My feeling is that SCL and SDA are not well initiated.
Best regards,
JM Roque