In our project we are using STM32F072 and have 2 Atmel AT24CM02 serial EEPROM (256KB,256 page) over i2c interface. I am using standard peripheral library 1.5 for developing firmware for this. I find strange behavior while testing this serial EEPROM under this environment.
I write two locations 0x0005 and 0x0009 with 0x44 and 0x55 respectively, when I read back I get both locations as 0x55. Typically it looks like one write gets into multiple locations of the page. If I read 0x0005 immediately after write, I get value 0x44.
See the sample test code, and complete driver code which is ported from peripheral library is attached. The PCLK clock runs at 3MHz and using i2c timing configuration tool, timings were calculated and put. I have another RTC chip on the same interface and it works perfectly fine. Tested both the serial EEPROM chips (one has A2 connected to VCC and other one to GND), and behavior is same.
Any help is appreciated.
/* Initialize the I2C EEPROM driver ----------------------------------------*/
/* First write in the memory followed by a read of the written data --------*/
/* Write on I2C EEPROM from sEE_WRITE_ADDRESS1 */
TxBuffer = 0x44;
TxBuffer = 0x55;
bytes = 1;
addr = 0x0005;
Delay_Ticks(10); //200ms delay, much larger than needed
printf("Write 1 complete\n\r");
bytes = 1;
addr = 0x0009;
printf("Write 2 complete\n\r");
num = 1;
sEE_ReadBuffer(&RxBuffer, 0x0005, (uint16_t *)(&num));
sEE_ReadBuffer(&RxBuffer, 0x0006, (uint16_t *)(&num));