Go Down

Topic: AT24C256 data buffer cause data corruption (Read 3540 times) previous topic - next topic

Authentic_KY

Oct 14, 2019, 03:53 am Last Edit: Oct 14, 2019, 04:02 am by Authentic_KY
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);
  }


Lucario448

#1
Oct 16, 2019, 02:42 am Last Edit: Oct 16, 2019, 02:46 am by Lucario448
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.
Are you sure those are just 6 bytes and no more? Wire's transmit buffer is 32 bytes large, and 2 are always occupied by the memory address; so anything beyond the 30th payload's byte is discarded and not actually transmitted.

I don't remember exactly, but... does these EEPROM have the annoying write page boundaries? If yes, then maybe you are just wrapping around one of those "pages"; causing the data chain to split up next to its two boundaries.
For example: if you try to write a chain (array) of 6 bytes at once and from address 63; you will notice only the first one appears written from that address; and the rest... well they actually aren't discarded, but overwrote address 0 to 4.

That's basically the annoyance of write pages, which never happens when writing one by one hence why it works fine the second way.

PD: if you didn't noticed by the example, your EEPROM's write pages are 64 bytes long so every multiple of 64 there's one of mentioned boundaries.

PD 2: those boundaries only apply to write operations, sequential reads aren't affected by this.

Go Up