Go Down

Topic: Read entire EEPROM and write everything back? (Read 1 time) previous topic - next topic

Glomby

hello,

I'm completly new to eeproms, that's why I'm struggeling a bit with getting done what I want.

The overall Task seems to be simple. I want to copy 512 Bytes from an EEPROM (Maxim DS2433) to the internal Memory of the Arduino and write it back to the same DS2433 EEPROM later. This is meant to be some Kind of reset procedure.

Due to my lack of experience with EEPROMS I'm stuck and need some good advice.

So what I did so far: I'm using the OneWire Library and started with one of the examples:

Code: [Select]
#include <OneWire.h>
OneWire ds(6);                    // OneWire bus on digital pin 6
void setup() {
  Serial.begin (9600);
}

void loop() {
  byte i;                         // This is for the for loops
  boolean present;                // device present var
  byte data[32];                  // container for the data from device
  byte leemem[3] = {              // array with the commands to initiate a read, DS250x devices expect 3 bytes to start a read: command,LSB&MSB adresses
    0xF0 , 0x00 , 0x00   };       // 0xF0 is the Read Data command, followed by 00h 00h as starting address(the beginning, 0000h)
  byte ccrc;                      // Variable to store the command CRC
  byte ccrc_calc;

  present = ds.reset();           // OneWire bus reset, always needed to start operation on the bus, returns a 1/TRUE if there's a device present.
  ds.skip();                      // Skip ROM search

  if (present == TRUE){           // We only try to read the data if there's a device present
    Serial.println("DS250x device present");
    ds.write(leemem[0],1);        // Read data command, leave ghost power on
    ds.write(leemem[1],1);        // LSB starting address, leave ghost power on
    ds.write(leemem[2],1);        // MSB starting address, leave ghost power on

    ccrc = ds.read();             // DS250x generates a CRC for the command we sent, we assign a read slot and store it's value
    ccrc_calc = OneWire::crc16(leemem, 3);  // We calculate the CRC of the commands we sent using the library function and store it

    if ( ccrc_calc != ccrc) {      // Then we compare it to the value the ds250x calculated, if it fails, we print debug messages and abort
      Serial.println("Invalid command CRC!");
      Serial.print("Calculated CRC:");
      Serial.println(ccrc_calc,HEX);    // HEX makes it easier to observe and compare
      Serial.print("DS250x readback CRC:");
      Serial.println(ccrc,HEX);
      return;                      // Since CRC failed, we abort the rest of the loop and start over
    }
   
    Serial.println("Data is: ");   // For the printout of the data
    for ( i = 0; i < 32; i++) {    // Now it's time to read the PROM data itself, each page is 32 bytes so we need 32 read commands
      data[i] = ds.read();         // we store each read byte to a different position in the data array
      Serial.print(data[i],HEX);       // printout in ASCII
      Serial.print(" ");           // blank space
    }
    Serial.println();
    delay(5000);                    // Delay so we don't saturate the serial output
  }
  else {                           // Nothing is connected in the bus
    Serial.println("Nothing connected");
    delay(3000);
  }
}


The example is based up on the DS250x Family so I got some CRC Errors. I changed the "ccrc_calc = OneWire::crc8(leemem, 3);" to "16" and got rid of the Errors. In fact I got some Output.

The Problem is that I know what's stored on the Chip and I'm just getting an Output like this:

Code: [Select]

DS250x device present
Data is:
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0


Maybe I've accidentally deleted the chip or the code isn't working. I just Need to store everything in HEX and write it back afterwards. Do you have any tips for me?

Thanks in advance

Grumpy_Mike

Quote
I want to copy 512 Bytes from an EEPROM (Maxim DS2433) to the internal Memory of the Arduino and write it back to the same DS2433 EEPROM later.

How can you do this? That chip has 4K of memory but the ardunio has only 2K of SRAM for everything?

Glomby

Okay your right. In fact I just have to copy a very small portion of these 512 bytes but I need to read out everything to get it. At least I want to read it out first to do some tests with it before I can continue with the copy it back part.

But I'm just getting those zeros and I have no Idea why that is. I don't even need to convert what's stored on the chip. I just need the pure HEX code.

Grumpy_Mike

I don't see how resting the one wire bus can possibly tell toy that you have a device present.
Code: [Select]
present = ds.reset();           // OneWire bus reset, always needed to start operation on the bus, returns a 1/TRUE if there's a device present.
  ds.skip();   


These devices have a unique very long address and you need to find the address of your device before you can talk to it. Look at the one wire bus examples. This normally involves scanning the bus to find the address, I don't se anything like that in your code.

Glomby

This code is one of the examples. It is an example where only one device is conntected to the bus, so you don't have to use their adresses. At least this is what the example says.

And from what I understand, when ds.reset(); returns a TRUE it has found one or more devices, but when you know there is just one device you are fine with this minor check.

And it seems like I'm actually reading the chip. I'm just getting zeros instead of the HEX Code I'm expecting. But shouldn't I get nothing or one of these debugging Errors when I'm not really conntected to the DS2433? instead?

Grumpy_Mike

Quote
This code is one of the examples. It is an example where only one device is conntected to the bus, so you don't have to use their adresses. At least this is what the example says.

Yes I have just checked and that is what it says. However, I notice in the comments that it is old, that is it is for the IDE version 022, there might be some incompatibility, I don't know.

Ether way what I would do is to run the code on this page http://playground.arduino.cc/Learning/OneWire and see if it finds the device. If it does then I wonder if the contents of the memory is zero. You could try writing just a byte and see.
It might also be worth printing out all the memory to see if it is all zeros.

AlxDroidDev

I have written R/W functions for the EEPROM in a Maxim DS1624. The code can be downloaded from this thread:
http://forum.arduino.cc/index.php/topic,126197.0.html

the DS1624 is a digital thermometer that also features 512 bytes of EEPROM.

I am inclined to believe that the R/W methods for the DS1624 and the DS2433 are quite similar. If they aren't, I've made my code easy enough to adapt to the specs of another IC.
Learn to live: Live to learn.
Showing off my work: http://arduino.cc/forum/index.php/topic,126197.0.html

Glomby

Thanks so far for your help guys but I got still no information out of my ds2433 but I figured something out.

Everywhere on the Internet one can find that you should connect your 1 wire device via a 4.7k pull up resistor. That's the easy part but not in my case. My EEPROM comes already hooked up on a board with a 4.7k resistor on it. I measured the resistor to make sure it's 4.7k when I realized it's a pull down resistor.

So I'm stuck here. It seems to be it wasn't about code it was all about the wiring. Now I have to figure out how to connect it to the Arduino with a 4.7k pull down resistor and not a pull up because I can't change the board.

craigcurtin

Cant you just get a simpler chip/board - one based on the24lcxxx range which runs on the i2c bus ?

Only cost a couple of bucks.

Craig

Go Up