DS2431 EEPROM : READ and Write

Hello, please, I have a problem regarding writing to a DS2431 EEPROM using the OneWire protocol and Arduino libraries. I think it’s a synchronization issue, because the write function sometimes works well, but most of the time, I can't write to the memory slot. I've tried adjusting the delay, but it doesn't work. I also use a 4.7k pull-up resistor. My circuit is correct, but I still have a writing problem. Please, can you help me?

#include <DS2431.h>

#include <OneWire.h>

#define Max_DEVICES 1

const int ONE_WIRE_PIN_1 = 9;

OneWire oneWire1(ONE_WIRE_PIN_1);

DS2431 eeprom1(oneWire1);

word address3 = 0;
void setup() {
    Serial.begin(9600);
    while (!Serial); // Attendre que la console série soit prête

    byte CycleCharge[] = {25,2};
    eeprom1.write(address3, CycleCharge, sizeof(CycleCharge));
    delay(7000); 

    byte NbCycleChargeR[2];
    eeprom1.read(address3, NbCycleChargeR, sizeof(NbCycleChargeR));
    //Serial.println("Charge Cycle avant : ");
    printBuffer(NbCycleChargeR, sizeof(NbCycleChargeR));

    // Vérifier si l'écriture a réussi
    if (NbCycleChargeR[0] != CycleCharge[0]) {
        Serial.println("Erreur d'écriture !");
    }
}

void loop() {}
void printBuffer(const uint8_t *buf, uint8_t len)
{
  for (int i = 0; i < len-1; i++)
  {
    //Serial.print(buf[i], HEX);
    Serial.print(buf[i]);
   // Serial.print(",");
  }
  Serial.println(buf[len-1]);
}```

Your topic has been moved. Please do not post in "Uncategorized"; see the sticky topics in Uncategorized - Arduino Forum.

Please edit your post, select all code and click the <CODE> button; next save your post. This will apply code tags so the code is easier to read, easier to copy and the forum software will display it correctly. Please read How to get the best out of this forum.

In the DS2431 library there is an example of a name test:
"DS2431_ReadWrite.ino".

Run the example and see what happens.

Ref:

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