Pages: [1]   Go Down
Author Topic: 24C08 Wiring & Sketch  (Read 715 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 2
Posts: 13
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hallo,

keine Ahnung, ob es irgend jemand interessiert. Da der 24C08 EEPROM doch etwas anders ist als die anderen EEPROMs, kopiere ich mein Sketch mal hierhin.
Da der 24C08 nur einen Adressbereich von einem Byte hat womit sich aber nicht der ganze Speicherbereich von 1024 Byte adressieren lässt, hat jeder EEPROM vier unterschiedliche I2C Adressen.  Es lassen sich max. zwei Chips benutzen, da nur ein Eingang für die I2C Adresse vorgesehen ist. Interessant an dem Chip ist, dass STM 1 Mio Schreib-/Löschzyklen garantiert. Da ich gestern lange gegrübelt habe und nichts brauchbares im Netz bzw auch falsche Infos hier im Forum fand, hier mal mein Sketch. Vielleicht hilft es jemanden wenn er nach Infos sucht.

Code:
/*
  Reading and writing data to 24C08 EEPROM over I2C
  CC0
 
  Datasheet for 24C08 http://www.datasheetcatalog.org/datasheets/134/80474_DS.pdf
 
  WIRING
            __ __
      PRE -|     |- VCC
      NC  -|     |- MODE
      E   -|     |- SCL
      VSS -|_____|- SDA
         
      PRE  = Write Protect              -> GROUND
      NC   = Not connected       
      E    = Chip Enable Input          -> first EEPROM -> GROUND for I2C addresses 0x50,0x51,0x52,0x53; second EEPROM -> 5V for I2C addresses 0x54,0x55,0x56,0x57
      VSS  = Ground                     -> GROUND
      VCC  = Supply Voltage             -> 5V
      MODE = Multibyte/Page Write Mode  -> GROUND (not used here)
      SCL  = Serial Clock               -> Analog PIN 5 (Uno)
      SDA  = Serial Data Address IN/OUT -> Analog PIN 4 (Uno)
 
 
*/

#include <Wire.h>     // for I2C

// variable to receive data coming from the EERPROMs
byte data_received=0;

// eeprom address array, use I2C scanner sketch to find the addresses. This array contains 2 chips with 4 device addresses (like virtual chips) each
byte chip[] = {0x50,0x51,0x52,0x53,0x54,0x55,0x56,0x57};



void setup()
{
  Serial.begin(9600); // for screen output
  Wire.begin();       // waking up I2C
  delay(1000);
  Serial.println("Setup finished");
}

void writeData(int device_address, byte memory_address, byte data)
// write one byte of data 'data' to eeprom memory address 'memory_address' to chip with I2C address 'device_address'
{
  Wire.beginTransmission(device_address);  // device address
  Wire.write(memory_address );             // memory address
  Wire.write(data);                        // data to send
  Wire.endTransmission();                  // end
  delay(10);
}

byte readData(int device_address, byte memory_address)
// reads one byte of data from memory location 'memory_address' in chip at I2C address 'device_address'
{
  byte result;  // return value
  Wire.beginTransmission(device_address); // device address
  Wire.write(memory_address);             // memory address
  Wire.endTransmission();                 // end
  Wire.requestFrom(device_address,1);     // get one byte of data from device
  if (Wire.available())
    result = Wire.read();
  return result;                          // return the read data byte
  delay(10);
}

void loop()
{
  // WRITING DATA

  int ascii_counter = 33;        // to see something we start with the first readable character in the ASCII table which is 33 == '!'
  Serial.println();
  Serial.print("Writing data ");
  Serial.println();
  for (int a=0; a<8; a++)                                    // loop to go through the address array of the eeprom i.e. chip[a]
  {
    for (int b=0; b<256;b++)                                 // each chip has one byte of addressable memory
    {
      writeData(chip[a],b,ascii_counter);                    // writing the value ascii_counter to chip chip[a] at address b
      Serial.print("chip :");                                // let's see what it did
      Serial.print(chip[a], HEX);
      Serial.print(" address :");
      Serial.print(b);
      Serial.print(" value :");
      Serial.println(char(ascii_counter));
      ascii_counter++;                                       // next character of ASCII table
      if (ascii_counter > 126) {ascii_counter = 33;};        // ASCII characters greater 126 are not visible, go back to the first readable character at 33
    }
    Serial.println();
  }
  delay(10000);                                              // let's wait some seconds

  // READING DATA
   
  Serial.println("Reading data...");
  for (int a=0; a<8; a++)                                    // same as above, we toogle through the 8 chips ....
  {
    Serial.print("Chip: ");
    Serial.println(chip[a],HEX);
    for (int b=0; b<256;b++)                                 // and all 256 addresses in each (virtual) chip...
    {
      data_received=readData(chip[a],b);                     // and read the data there....
      Serial.print(char(data_received));                     // and print it to serial....
    }
    Serial.println();                                        // new line for each chip
  }
// since the chip has only a limited number of write cycles, we don't want to write again and again. Let's end the sketch
  do                                                         
  {
    delay(10000);
  } while ( 1 != 0);
}
Logged

northern germany
Offline Offline
Jr. Member
**
Karma: 2
Posts: 94
Ausbildung: Funkmechaniker, Systemadministrator
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Danke für die Infos.
Im Datenblatt für den 24C65 (hat den schon mal jemand mit einem Arduino genutzt?) ist folgendes angegeben:
Code:
Endurance:
- 10,000,000 E/W cycles guaranteed for High Endurance Block
- 100,000 E/W cycles guaranteed for a Standard Endurance Block

Kann mir das mit dem "High Endurance Block" und dem "Standard Endurance Block" bitte mal jemand erklären?

Dirk
« Last Edit: February 02, 2013, 12:46:44 pm by dischneider » Logged

using arduino leonardo
--
tomorrow today will only be yesterday, so live your life today!

Offline Offline
Newbie
*
Karma: 2
Posts: 13
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Danke für die Infos.
Im Datenblatt für den 24C65 (hat den schon mal jemand mit einem Arduino genutzt?) ist folgendes angegeben:
Code:
Endurance:
- 10,000,000 E/W cycles guaranteed for High Endurance Block
- 100,000 E/W cycles guaranteed for a Standard Endurance Block

Kann mir das mit dem "High Endurance Block" und dem "Standard Endurance Block" bitte mal jemand erklären?

Dirk

Du hast das falsche Datasheet verlinkt. Im richtigen Datasheet
http://www.datasheetcatalog.org/datasheet2/6/0r8hiw9dchrha5s4p07uhzqe7sfy.pdf
steht:
"The 24XX65 offers a relocatable
4K bit block of ultra-high-endurance memory for data
that changes frequently. The remainder of the array, or
60K bits, is rated at 1,000,000 erase/write (E/W) cycles
ensured."

Sprich, es ist ein spezieller Speicherbereich der länger hält.
Logged

northern germany
Offline Offline
Jr. Member
**
Karma: 2
Posts: 94
Ausbildung: Funkmechaniker, Systemadministrator
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

prima, danke für die Info.

Ich meinte eigentlich dieses Datenblatt, habs mal im Ursprungspost korrigiert.

Dirk
 
Logged

using arduino leonardo
--
tomorrow today will only be yesterday, so live your life today!

Pages: [1]   Go Up
Jump to: