Hello Profesionals
can you please full and correct describe how to write a value to the EEPROM?
It is absolutely not described in the datasheet.
Here's my Code:
void pgaEEPROMspeichern()
{
delay(20);
write(0x5, 0x89, 0b00000100); // ERASE_AND_PROGRAMM
delay(20);
pgaEEPROMCalcCRC(); //???
delay(20);
write(0x5, 0x8A, 0b00000001); //Calculate CRC
delay(20);
Serial.print("CRCOK=");
Serial.println(read(0x5,0x8C),BIN); //Read CRCOK
}
void pgaEEPROMcacheLaden(uint8_t cellAdresse) //irgendeine Adresse aus dem 8er Block
{
write(0x0, 0x0C, 0b00000011);
uint8_t addr;
addr = cellAdresse >> 3;
uint8_t startAdresse = addr << 3; //auf 8er block anpassen.
Serial.print("Startbits = ");
Serial.print(addr, BIN);
Serial.print(" = ");
Serial.println(startAdresse, HEX);
write(0x5, 0x88, addr); //oberste 4bit der EEPROM Addresse
for (int i = 0; i < 8; i++)
{
Serial.print("CacheAddr = ");
Serial.print(0x80 + i, HEX);
Serial.print(" = ");
Serial.println(read(0x5, startAdresse + i), BIN);
write(0x5, 0x80 + i, read(0x5, startAdresse + i)); //EEPROM auslesen und in EEPROM Cache laden
}
//write(0x5, 0x89,0b00000100); // ERASE_AND_PROGRAMM
}
void pgaEEPROMCalcCRC(){
uint8_t currentCRC8 = 0xFF; // Current value of CRC8
for (int i = 0; i < 127; i++)
{
uint8_t C=read(0x5, i);
uint8_t D=currentCRC8;
uint8_t nextCRC8=0;
bitWrite(nextCRC8,0,(bitRead(D,7)^bitRead(D,6)^bitRead(D,0)^bitRead(C,0)^bitRead(C,6)^bitRead(C,7)));
bitWrite(nextCRC8,1,(bitRead(D,6)^bitRead(D,1)^bitRead(D,0)^bitRead(C,0)^bitRead(C,1)^bitRead(C,6)));
bitWrite(nextCRC8,2,(bitRead(D,6)^bitRead(D,2)^bitRead(D,1)^bitRead(D,0)^bitRead(C,0)^bitRead(C,1)^bitRead(C,2)^bitRead(C,6)));
bitWrite(nextCRC8,3,(bitRead(D,7)^bitRead(D,3)^bitRead(D,2)^bitRead(D,1)^bitRead(C,1)^bitRead(C,2)^bitRead(C,3)^bitRead(C,7)));
bitWrite(nextCRC8,4,(bitRead(D,4)^bitRead(D,3)^bitRead(D,2)^bitRead(C,2)^bitRead(C,3)^bitRead(C,4)));
bitWrite(nextCRC8,5,(bitRead(D,5)^bitRead(D,4)^bitRead(D,3)^bitRead(C,3)^bitRead(C,4)^bitRead(C,5)));
bitWrite(nextCRC8,6,(bitRead(D,6)^bitRead(D,5)^bitRead(D,4)^bitRead(C,4)^bitRead(C,5)^bitRead(C,6)));
bitWrite(nextCRC8,7,(bitRead(D,7)^bitRead(D,6)^bitRead(D,5)^bitRead(C,5)^bitRead(C,6)^bitRead(C,7)));
currentCRC8=nextCRC8;
}
Serial.print("Berechneter CRC=");
Serial.println(currentCRC8,BIN);
write(0x5,0x8D,currentCRC8);
Serial.print("gelesener CRC=");
Serial.println(read(0x5,0x8D),BIN);
}
What is the procedure to e.g. write a 0b01000000 to 0x4000000E (G0_MSB)?
My steps are:
-calc upper 3 bit (with 0x0E >> 3 = 1) and write to (0x5, 0x88)
-read from (0x5, 0x08 to 0x0F) and write to EEPROM Cache (0x5, 0x80 to 0x87)
-write 0b01000000 to (0x5,0x82)
i read all 8 byte and write only 1 because i only want to change 1.
-write(0x5, 0x89, 0b00000100); // ERASE_AND_PROGRAMM
After this i every time get a CRCOK=0, writing back the default values everything is okay?
Is there to do a CRC Calculation by me and how exactly?
On the Datasheet Page 63 the EEPROM_CRC_VALUE Register is all R, so it doesn't look like I'm supposed to be writing data.
i tried to translate the pseudocode to C++ but it is not very specific for which data and when to do.
i tried only for the EEPROM Cache, for the whole EEPROM (0x0 to 0x7F) or without CRC itself (0x0 to 0x7E). before or after ERASE_AND_PROGRAMM. nothing works...