This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts
This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Unusual TWI/I2C Problem

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, &reg, 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);

    }
}
Parents
  • It is a sad fact of life that some manufacturers will specify I2C addresses as 0xa0 for write and 0xa1 for read, whereas others use the 7 bit form, which in that case would be 0x50. The safe way is to examine the data-sheet, where there will often be a drawing of the actual waveform/timing diagram.

Reply
  • It is a sad fact of life that some manufacturers will specify I2C addresses as 0xa0 for write and 0xa1 for read, whereas others use the 7 bit form, which in that case would be 0x50. The safe way is to examine the data-sheet, where there will often be a drawing of the actual waveform/timing diagram.

Children
No Data
Related