Im working on a mechanical teaching device, a simple one. Using AT24c256 to extend my storage and Arduino UNO as controller . It generates lots of errors using buffer, and after i have the problem figured out, send only data a time rather than 6, the problem got sorted out . it seems bizarre to me.
I have a very simple algorithm to pinpoint some errors and dump corrupted data, but they are just too much and there isn't any pattern.
functions operating EEPROM is posted below.
The one that useing buffer and causes data corruption:
void writePostureEEPROM(long eeAddress) //use buffer cause data corrption
{
digitalWrite(Write_enable_pin,LOW);
Wire.beginTransmission(EEPROMADDR);
Wire.write((int)(eeAddress >> 8 )); // MSB
Wire.write((int)(eeAddress & 0xFF)); // LSB
for (byte x = 0 ; x < POSTUREEEPROMBUFFER_BYTE; ) {Wire.write((uint8_t)EEpromWritebuffer[ x ]);Serial.print((uint8_t)EEpromWritebuffer[ x ]);Serial.print(","); x++;delay(5); }
Wire.endTransmission();
digitalWrite(Write_enable_pin,HIGH);
}
Another one that is fine
void writePostureEEPROM(long eeAddress)
{
digitalWrite(Write_enable_pin,LOW);
for (int x = 0 ; x < POSTUREEEPROMBUFFER_BYTE ; )
{
Wire.beginTransmission(EEPROMADDR);
long RRR = eeAddress + x ;
Wire.write((int)(RRR >> 8 )); // MSB
Wire.write((int)(RRR & 0xFF)); // LSB
Wire.write((uint8_t)EEpromWritebuffer[ x ]);
Wire.endTransmission();
Serial.print((uint8_t)EEpromWritebuffer[ x ] );
Serial.print(",");
delay(5);
x++;
}
digitalWrite(Write_enable_pin,HIGH);
}