Need to read/write DS2431 via Arduino

Hi,

I have tried a lot of codes and circuit connections. But not able to read or write to my single wire ds2431 EEPROM

Please can someone guide me with circuit connections and code to read and write to DS2431

Thanks

Have you used the OneWire library?
I’ve used that without problems for DS2433 devices.

I tried it , but it was not detecting my IC

Can you provide me with your sample code

And power and data pin I connected pull up resistor of 5K ohm

I can’t give you the full code, but see if you can make sense of this
[uncompiled, untested]

#include <OneWire.h>

byte addr[8];

// DS2433 constants -- this will need to be adjusted for DS2431
const int BITS_PER_DEVICE = 4096;

const int BITS_PER_PAGE   = 256;
const int BYTES_PER_PAGE  = BITS_PER_PAGE / 8;
const int N_PAGES         = BITS_PER_DEVICE / BITS_PER_PAGE; 

// EEPROM commands
const byte WRITE_SPAD  = 0x0F;
const byte READ_SPAD   = 0xAA;
const byte COPY_SPAD   = 0x55;
const byte READ_MEMORY = 0xF0;


OneWire EEPROM(12); // put it on pin 12

void setup () 
{
  Serial.begin(57600);
  if ( !EEPROM.search(addr)) {
      Serial.print(F("No more addresses.\n"));
      EEPROM.reset_search();
      for (;;) ;
  }
  info ();
}

void loop ()
{
  // whatever
}

static void verify (byte* sourceData)
{
  const int BUF_SIZE = 16;
  byte edata [BUF_SIZE];
  byte errorFound = 0;
  
  Serial.print (F("Data:"));
  for (int i = 0; i < 512; i += BUF_SIZE) {
    readMem (i, edata, BUF_SIZE);
    dumpRow (i, edata, BUF_SIZE, false);
    int pos = compareBuf (edata, &sourceData [i], BUF_SIZE);
    if (pos) {
      errorFound = 1;
      pos--;
      Serial.println ();
      for (int i = 0; i < pos; ++i) {
        Serial.print (F("   "));
      }
      Serial.print (F("^^\nMismatch at "));
      Serial.println (pos);
      Serial.print (F("expected "));
      print2Hex (sourceData [i + pos]);
      Serial.print (F(" read "));
      print2Hex (edata[i]);
      Serial.println ();
      break;
    }
  }
  if (errorFound == 0) {
    Serial.print (F("\nVERIFIED OK!"));
  }
}

/*

*/
static void floodFill (byte val)
{
  Serial.print (F("Filling with 0x"));
  print2Hex (val);
  Serial.println ();
  byte writeBuffer [BYTES_PER_PAGE];
  for (int page = 0; page < N_PAGES; ++page) {
    memset (writeBuffer, val, BYTES_PER_PAGE);
    writePage (page, writeBuffer); 
  }
}


void readMem (int memAddr, byte* buf, int len)
{
  EEPROM.reset();
  EEPROM.select(addr);    
  EEPROM.write (READ_MEMORY, 1);
  EEPROM.write (lowByte (memAddr), 1);
  EEPROM.write (highByte (memAddr), 1);

  for (int i = 0 ; i < len; ++i) {
    buf [i] = EEPROM.read ();
  }
}

/*

*/
void writeReadScratchPad(int memAddr, byte* data)
{
  EEPROM.reset();
  EEPROM.select(addr);
  EEPROM.write(WRITE_SPAD,1);  // Write ScratchPad
  EEPROM.write (lowByte (memAddr), 1);
  EEPROM.write (highByte (memAddr), 1);
  for (int i = 0; i < BYTES_PER_PAGE; i++)
    EEPROM.write(data[i],1);  
  
  EEPROM.reset();
  EEPROM.select(addr);    
  EEPROM.write(READ_SPAD);         // Read Scratchpad
  
  for (int i = 0; i < BYTES_PER_PAGE; i++)     
    data[i] = EEPROM.read();
}

/*

*/
void copyScratchPad(byte* data)
{
  EEPROM.reset();
  EEPROM.select(addr);
  EEPROM.write(COPY_SPAD, 1);  // Copy ScratchPad
  EEPROM.write(data[0],1); 
  EEPROM.write(data[1],1);  // Send TA1 TA2 and ES for copy authorization
  EEPROM.write(data[2],1); 
  delay(25); // Waiting for copy completion
  //Serial.print("Copy done!\n");
}

/*

*/
void writePage(byte page, byte* buffer)
{
  if (page < 0 || page >= N_PAGES) //There are 16 row of 32 bytes in the main memory
    return;                //The remaining are for the 64 bits register page
    
  writeReadScratchPad(page * BYTES_PER_PAGE, buffer);
  copyScratchPad(buffer);
}

/*

*/
byte compareBuf (byte* src0, const byte* src1, int len)
{
  for (int i = 0; i < len; ++i) {
    if (src0 [i] != src1 [i]) 
      return i + 1;
  }
  return 0;
}

/*

*/
void printAddress (byte* buff, int size)
{
  dumpRow (0, buff, size, false);
}

/*

*/
static void print2Hex (byte val)
{
  if (val < 16)
    Serial.print("0");
  Serial.print(val, HEX);
}

/*

*/
static void print4Hex (unsigned int base)
{
  print2Hex (highByte (base));  
  print2Hex (lowByte (base));  
}

/* 
  Dump a single row of an array in a C source compatible style
*/
static void dumpRow (int base, byte* buff, int size, boolean Cstyle)
{
  Serial.println ();
  if (Cstyle) {
    Serial.print ("/*");
    print4Hex (base);
    Serial.print("*/ ");
  }  
  for (int i = 0; i < size; ++i) {
    if (Cstyle)
      Serial.print("0x");
    print2Hex (buff[i]);
    if (Cstyle)
     Serial.print(",");
    Serial.print(" ");
  }
  if (Cstyle) {
     // pad short lines here... 
    for (int i = 0; i < 16 - size; ++i) {
      Serial.print ("     ");
    }  
    Serial.print("// |");
    for (int i = 0; i < size; ++i) {
      if (buff [i] >= 0x20 && buff [i] <= 0x7f)
        Serial.write (buff [i]);
      else
        Serial.print(".");
    }
    for (int i = 0; i < 16 - size; ++i) {
      Serial.print (" ");
    }  
    Serial.print("|");
  }
}
/*
  Dump any sized buffer (up to 32k)
*/
static void dumpBuffer (byte* buff, int size)
{
  int rows      = size / 16;
  int leftovers = size % 16;
  int base      = 0;
  for(int i = 0; i < rows; i++) {
    base = i * 16;
    dumpRow (base, &buff [base], 16, true);
  }
  if (leftovers){
    dumpRow (base, &buff [base], leftovers, true);
  }  
}

/*
  Simply report device parameters as aide-memoire
*/
static void info ()
{
  Serial.print (F("BITS_PER_DEVICE "));
  Serial.println (BITS_PER_DEVICE);
  Serial.print (F("BITS_PER_PAGE "));
  Serial.println (BITS_PER_PAGE);
  Serial.print (F("BYTES_PER_PAGE "));
  Serial.println (BYTES_PER_PAGE);
  Serial.print (F("N_PAGES "));
  Serial.println (N_PAGES);
}

/*
  identify the device from the address
*/
static void ident (byte* address)
{
  Serial.print(F("\nDevice is "));
  switch (address [0]) {
    case 0x10:
      Serial.println(F("DS18S20 family device."));
    break;  
    case 0x28:
      Serial.println(F("DS18B20 family device."));
    break;  
    case 0x23: 
      Serial.println(F("Maxim EEPROM."));
    break;
    default:
      Serial.print(F("not recognized: 0x"));
      Serial.println(address[0], HEX);
      return;
  }  
}