I2C problem

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

I2C problem

1,013 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Genesy on Mon Apr 22 02:55:22 MST 2013
Hi,
I have a problem with I2C. In my project I would to write same parameter in memory when I received a command from CANOpen register. Some command call two I2C Write consecutive and in this case the parameter is not written. On other occasions I resolved the problem with a empty waiting cycle like this:

[FONT=Courier New]void EEPROM_delayBetweenOp(){
    volatile int i;
    for ( i = 0; i < 0x20000; i++ );
}[/FONT]

but not in this case.
Have you a workaround for this problem?
0 Kudos
Reply
3 Replies

981 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by cmcquaid on Tue Apr 23 10:51:04 MST 2013

Quote: Genesy
Can you give me an example, please?
When the write not work it return the status code 11 that is a TIMEOUT error. Perhaps because in the meantime I read even at a rate of 300ms by an accelerometer always I2C and perhaps write command found the bus busy. How can I fix?



It is not the I2C bus that is busy, it is your EEPROM.
When you get a timeout, that is just the EEPROM's way of saying "try again later".

You can use a variable to keep track of how much data you need to write. Each time through your [FONT=Courier New]while[/FONT] loop, if you have data, try to write to the EEPROM. If the write succeeds, decrement your variable by the amount of data written.
0 Kudos
Reply

981 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Genesy on Tue Apr 23 01:52:29 MST 2013
Can you give me an example, please?
I use the I2C driver in I2C example that have this function:

[FONT=Courier New][SIZE=2]uint32_t I2CEngine( void )
{
  RdIndex = 0;
  WrIndex = 0;

  /*--- Issue a start condition ---*/
  LPC_I2C->CONSET = I2CONSET_STA;    /* Set Start flag */

  I2CMasterState = I2C_BUSY;   

  while ( I2CMasterState == I2C_BUSY )
  {
    if ( timeout >= MAX_TIMEOUT )
    {
      I2CMasterState = I2C_TIME_OUT;
      break;
    }
    timeout++;
  }   
  LPC_I2C->CONCLR = I2CONCLR_STAC;

  return ( I2CMasterState );
}[/SIZE][/FONT]

When the write not work it return the status code 11 that is a TIMEOUT error. Perhaps because in the meantime I read even at a rate of 300ms by an accelerometer always I2C and perhaps write command found the bus busy. How can I fix?
0 Kudos
Reply

981 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by cmcquaid on Mon Apr 22 10:46:07 MST 2013
It takes a finite amount of time to write to an EEPROM, typically on the order of milliseconds. This is likely to be longer than the time between consecutive instructions on your microcontroller. It is common for EEPROMs not to acknowledge their address during a programming cycle, so you can wait for an ACK before proceeding rather than having a delay.

You should check your specific EEPROM datasheet for details.
0 Kudos
Reply