I2C example problem

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

I2C example problem

379 Views
lpcware
NXP Employee
NXP Employee
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);
0 Kudos
5 Replies

329 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by tha on Tue Oct 08 17:35:20 MST 2013
You can poll the STAT register and read out the status code.  The status code will tell you if an ACK was received or not.  Refer to the I2C chapter in the User Manual.
0 Kudos

329 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Genesy on Tue Oct 08 06:45:29 MST 2013
Thank you very much.  I had missed this thing.
Another problem that I have is when I do two consecutive write. I use a delay between two write whit a for cycle to 20000 like in the example but it doesn't work always.
How can I do an ack polling after write using the I2CEngine?
0 Kudos

329 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by serge on Tue Oct 08 00:34:51 MST 2013
Or you could consider to use FRAM memory. It is a little more expensive but it has no waitstates when writing.
The FM24C04B-G is a perfect replacement for your PCF8594 (check pinout)
0 Kudos

329 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by serge on Tue Oct 08 00:31:42 MST 2013
Or if you have problems with the waitstates you could consider fram-memory (is a little more expensive) but it has no waitstates.

The FM24C04 is a perfect substitute.
0 Kudos

329 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by wmues on Tue Oct 08 00:18:20 MST 2013
Have you read the data sheet of your EEPROM?

You can write up to 8 bytes at once (page write operation). Then you must wait 32ms until you can write/read again.
0 Kudos