Move one memory location

Hi, every time I save it to the EEPROM, my data is shifted by one place, 
so it doesn't save properly, I keep looking at it and I don't know what
I'm ignoring :D, More eyes see more, so I will be very happy for any comment :).
From my point of view, it seems that it will omit one place at the beginning
and write it down to another and then it will not stay for the last one :)
I'm saving this -> please note that it starts with 20 and ends with FD
20202020205AFF00103037303730375A0501010059380000000069C100A598FD0501010059380000000069C100A597FD0401ED04FD3D14F628A7B80001003BFB0401ED04FD3D14F628A7B80001003AFB07026C02D901FDFF3004430C070024FC00008B0D1E0E0000470300000000ECFE05040081FE0000040000EC2C000055FD05040081FE0000040000EC2C000055FD0080808080000080008080FF000078FB0080808080000080008080FF000078FB0507000010544D42444C0100000065FE0507000010544D42444C0100000065FE323155333838383433353437530105FD323155333838383433353437530105FD4B5A375A30473433373037323001DCFC4B5A375A30473433373037323001DCFC000011136E0700000000000000001111FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF0101000000000000000000000000EAFF0107000000000000000000000000E3FF0000000000000000000000000000EAFF000002226C001C000311D1023C0416FE4445028897018700000000000000B6FD0000000000000000000000000000E7FF0000000000000000000000000000E6FF0000000000000000000000000000E5FF0000303641393036303332484A2057FD303030310000000000000000000022FF01020001010A81FE007AB300000027FD01020001010A81FE007AB300000027FD
and after reading it it shows me this -> F starts and then up to 20 so 
it's shifted one place -> and F ends, so she omitted the letter D
F20202020205AFF00103037303730375A0501010059380000000069C100A598FD0501010059380000000069C100A597FD0401ED04FD3D14F628A7B80001003BFB0401ED04FD3D14F628A7B80001003AFB07026C02D901FDFF3004430C070024FC00008B0D1E0E0000470300000000ECFE05040081FE0000040000EC2C000055FD05040081FE0000040000EC2C000055FD0080808080000080008080FF000078FB0080808080000080008080FF000078FB0507000010544D42444C0100000065FE0507000010544D42444C0100000065FE323155333838383433353437530105FD323155333838383433353437530105FD4B5A375A30473433373037323001DCFC4B5A375A30473433373037323001DCFC000011136E0700000000000000001111FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF0101000000000000000000000000EAFF0107000000000000000000000000E3FF0000000000000000000000000000EAFF000002226C001C000311D1023C0416FE4445028897018700000000000000B6FD0000000000000000000000000000E7FF0000000000000000000000000000E6FF0000000000000000000000000000E5FF0000303641393036303332484A2057FD303030310000000000000000000022FF01020001010A81FE007AB300000027FD01020001010A81FE007AB300000027F

I have this code

uint8_t writeByteAt(uint8_t cs, uint16_t adr, char d)
{
  SPI.beginTransaction(SPISettings(20000000, MSBFIRST, SPI_MODE0));
  digitalWrite(cs, LOW);
  SPI.transfer(WREN); 
  digitalWrite(cs, HIGH);
  delay(10);
  digitalWrite(cs, LOW);
  uint8_t a = highByte(adr);
  a = a << 3;  
  a = a | WRITE;  
  SPI.transfer(a); 
  SPI.transfer(lowByte(adr)); 
  a = SPI.transfer(d);
  digitalWrite(cs, HIGH);
  delay(15);
  SPI.endTransaction();

  return a;
}


int8_t intValueOfHexaKey(char c)
{
  if ((c >= '0') && (c <= '9')) return c - '0';
  if ((c >= 'A') && (c <= 'F')) return c - 'A' + 10;
  return -1; 
}
void loop()
{
digitalWrite(posPIN, LOW);
      digitalWrite(negPIN, HIGH);
      delay(20);
      char dump[EEPROMSIZE] = "0";
      char readData[EEPROMSIZE * 2] = "0"; 
      Serial.readBytes(readData, EEPROMSIZE * 2); 
      for (int i = 0; i < EEPROMSIZE; i++)
      {
        dump[i] = intValueOfHexaKey(readData[i * 2 +1]) + 16 * intValueOfHexaKey(readData[i * 2]); 
        Serial.print(dump[i]); 
      }
      char ch[30];
      for (uint16_t i = 0; i < EEPROMSIZE; i++)
      {
        sprintf(ch,"%02X",writeByteAt(csPIN,i,dump[i]));
      }

      delay(500);
      digitalWrite(negPIN, LOW);
      digitalWrite(posPIN, HIGH);
}

Better ? :slight_smile:

Strip your code and just write to the EEPROM locations numbers from 0 to 99.
And read it back.

That will tell you where you coding error is.

I did this, but it's still shifted by one square.
digitalWrite(posPIN, LOW);
      digitalWrite(negPIN, HIGH);
      delay(20);
      char dump[512];
      char readData[1024];
      Serial.readBytes(readData, 1024); 
     /* for (int i = 0; i < 512; i++)
      {
        dump[i] = intValueOfHexaKey(readData[i*2+1]) + 16 * intValueOfHexaKey(readData[i*2]);
        Serial.print(dump[i]);
      }*/
      char ch[30];
      for (uint16_t i = 0; i < 512; i++)
      {
      //Here is problem 
        dump[i] = intValueOfHexaKey(readData[i*2+1]) + 16 * intValueOfHexaKey(readData[i*2]);
        Serial.print(dump[i]);
        sprintf(ch,"%02X",writeByteAt(csPIN,i,dump[i]));
      }

      delay(500);
      digitalWrite(negPIN, LOW);
      digitalWrite(posPIN, HIGH);
is there a problem with this feature?
dump[i] = intValueOfHexaKey(readData[i*2+1]) + 16 * intValueOfHexaKey(readData[i*2]);
What exactly do you mean by that, will you try to give me an example?

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.