lpcware

I2C example problem

Discussion created by lpcware Employee on Jun 15, 2016
Latest reply on Jun 15, 2016 by lpcware
Content originally posted in LPCWare by Genesy on Mon Oct 07 10:01:43 MST 2013
Good morning,
I tried the I2C project example for write an I2C EEprom like PCF8594. If I write only 10
byte all it's ok, but if i write 100 byte it doesn't work. In the example there is a delay after
write with this note:
"/* Be careful with below fixed delay. From device to device, or
  even same device with different write length, or various I2C clock,
  below delay length may need to be changed accordingly. Having
  a break point before Write/Read start will be helpful to isolate
  the problem. */
  for ( i = 0; i < 0x2000; i++ );/* Delay after write */"
I tried to increase this delay very much (2000000) but it doesn't work yet.

What can be the problem? How is possible to calculate the required delay?

This is the code where I only wrapped the I2C function from the original example:

uint8_t data_to_write[MAX_DATA_READ];
   for (i = 0; i < MAX_DATA_READ; i++ ){
   data_to_write = 0x00;
   }
   state = I2CWrite(PCF8594_ADDR, 0, 2, MAX_DATA_READ, data_to_write);


  /* Be careful with below fixed delay. From device to device, or
  even same device with different write length, or various I2C clock,
  below delay length may need to be changed accordingly. Having
  a break point before Write/Read start will be helpful to isolate
  the problem. */
  for ( i = 0; i < 0x2000; i++ );/* Delay after write */

  /* Write SLA(W), address, SLA(R), and read one byte back. */
  uint8_t data_read[MAX_DATA_READ];
  for (i = 0; i < MAX_DATA_READ; i++ ){
  data_read = 0;
  }
  state = I2CRead(PCF8594_ADDR, 0, 2, MAX_DATA_READ, data_read);

Outcomes