I2C & LPC1347 - Does the i2c.c::I2CStart() routine need a delay inserted (LPCXpresso board)?

Discussion created by lpcware Employee on Jun 15, 2016
Latest reply on Jun 15, 2016 by lpcware
Content originally posted in LPCWare by mathseng on Wed Oct 09 16:39:58 MST 2013
Does anyone have a better 'fix' for an issue I am facing, where to get reliable communications, I have inserted a delay in the I2Start() routine?

Description of the Problem:
On an LPCXpresso LPC1347 testbed, and using a SE95 temperature sensor wired exactly as per SE95 Section 14 Application Information, Fig 18 Typical application circuit, I am finding that the first READ of the SE95 succeeds, but all subsequent reads fail.

A solution which appears to solve the Problem:
I added line which re-uses the now discarded timeout variable:
  for (timeout = 0; timeout < STARTDELAY; ++timeout);
My Revised routine is below.

I2C communication is apparently reliable with a STARTDELAY value of 1000, for the simple testbed case and where the clock is not changed from default start value of 12MHz. I have set STARTDELAY to be 5000 in my code.

Why did I pick this particular solution?
Using the Microchip Pickit Serial Analzyer, I noted that the START lasts 300uS, while the LPC1347 uses timing which looks like the I2C timing diagram in the datasheet, Fig 24. I2C-bus pins clock timing (actually showing as 5.6uS).
I was surprised that this change gave desired results, since the START length is determined elsewhere.

Note: There is no NO visible difference in the timing display from applying a STARTDELAY - values as large as 500000 appearing to have no other effect than to ensure consistent I2C operation. Attached is a copy of the timing display, with STARTDELAY at 500000, and a timing display when STARTDELAY is 1 and the read fails on the second and subsequent reads.

Note #2: {unchecked and untested opinion :) }
I2CSlaveBuffer could possibly over-run in state 50.  i2c.c::void I2C_IRQHandler(void)
Data is read from register BEFORE checking whether number of bytes has been exceeded.

uint32_t I2CStart( void )
  uint32_t timeout = 0;
  uint32_t retVal = FALSE;

  /*--- Issue a start condition ---*/
  LPC_I2C->CONSET = I2CONSET_STA;/* Set Start flag */
  /*--- Wait until START transmitted ---*/
  while( 1 )
if ( I2CMasterState == I2C_STARTED )
  retVal = TRUE;
  // found issue reading SE95 - this delay seemed to allow it to work
  for (timeout = 0; timeout < startDelay; ++timeout);
if ( timeout >= MAX_TIMEOUT )
  retVal = FALSE;
  return( retVal );