Hello
I've been experiencing an unusual problem using the TWI/I2C library for the nRF51-DK board. Basically, I found that I need to shift my device address to the left by 1-bit in order for the board and the device to communicate and I don't understand why?
The IC is an ADT7420 temperature sensor, its default address is 0x48 and its device id register is found at 0x0B. I was attempting to read this device ID to verify the operation of the chip, however the chip failed to respond unless I shifted the address to the left by 1 bit (i.e. 0x48<<1 which equals 0x90), however with a different IC (a TMP007 IR sensor) there was no problem. I decided to try shifitng the bits after looking at the SDA and SCL waveforms on an oscilloscope and they seemed out of alignment by one clock cycle. I also tested the ADT7420 with an Arduino and I had no problem with the normal address of 0x48.
I'm using the latest version of the SDK, Keil v5 and the I2C is operating at 100 kHz.
Here's a simplified section of code that I'm using:
bool readI2cData(uint8_t address, uint8_t reg, uint8_t* data, uint8_t len)
{
// initialize data to zero so we don't return random values.
for (int i = 0; i < len; i++)
{
data[i] = 0;
}
// Write: register address we want to start reading from
if (twi_master_transfer(address, ®, 1, TWI_DONT_ISSUE_STOP))
{
// Read: the number of bytes requested.
if (twi_master_transfer(address | TWI_READ_BIT, data, len, TWI_ISSUE_STOP))
{
// Read succeeded.
return true;
}
}
// read or write failed.
return false;
}
int main(void)
{
twi_master_init(); // Initialise I2C bus
while (true)
{
uint8_t temp_read[2];
readI2cData(0x48<<1, 0x0B, temp_read, 2);
nrf_delay_ms(100);
}
}