Willkommen auf unserem Seminar-Blog

Immer auf dem aktuellen Stand bleiben

Dieser Seminar-Blog befindet sich noch im Aufbau und wird in den kommenden Tagen entsprechend verfeinert.

Member Login

Lost your password?

Registration is closed

Sorry, you are not allowed to register by yourself on this site!

You must either be invited by one of our team member or request an invitation by email at viad.info {at} zhdk {dot} ch.

EEPROM-Code

EEPROM-Code

On the ControllerBoard is an EEPROM from Atmel, the AT24C1024B, with 1MBit of Memory(128KBytes). This chip can be accessed with i2c, a 2-Wire chip protocol. There is already a library for this chip available: http://www.arduino.cc/playground/Code/I2CEEPROM24C1024
#include <WProgram.h>
#include <Wire.h>          // i2c lib
#include <E24C1024.h>      // eeprom lib

unsigned long errors = 0;
unsigned long address = 0;

// Set to a higher number if you want to start at a higher address.
#define MIN_ADDRESS 0

// Upper boundary of the address space.  Choose one.
#define MAX_ADDRESS 131072 // 1 device
//#define MAX_ADDRESS 262144 // 2 devices
//#define MAX_ADDRESS 393216 // 3 devices
//#define MAX_ADDRESS 524288 // 4 devices

#define TEST_SIZE  16

void setup()
{
  // enable eeprom
  // this has to be set before accessing the eeprom,
  // otherwise the eeprom has no power, check the schematics
  pinMode(23, OUTPUT);     //
  digitalWrite(23, LOW);   // a low on D23 enables the eeprom

  // test the eeprom, write to the eeprom + read out of it
  Serial.begin(9600);
  Serial.println("---------------------------");
  Serial.println("EEPROM Test");
  writeByByteTest();
  readByByteTest();
}

void loop()
{
}

void writeByByteTest()
{
  errors = 0;
  Serial.println("--------------------------------");
  Serial.println("Write to EEPROM:");

  for (address = MIN_ADDRESS; address < TEST_SIZE; address++)
  {
    // write to the eeprom
    EEPROM1024.write(address, (uint8_t)(address));
    Serial.print(".");
  }
  Serial.println();
}

void readByByteTest()
{
  errors = 0;
  Serial.println("--------------------------------");
  Serial.println("Read from EEPROM:");
  uint8_t data;
  for (address = MIN_ADDRESS; address <TEST_SIZE; address++)
  {
    // read out the eeprom data
    data = EEPROM1024.read(address);

    // check for errors
    if (data != (uint8_t)(address))
    {
      Serial.println();
      Serial.print("Address: ");
      Serial.print(address);
      Serial.print(" Should be: ");
      Serial.print((uint8_t)(address), DEC);
      Serial.print(" Read val: ");
      Serial.println(data, DEC);
      errors++;
    }
    else
      Serial.print(".");
  }
  Serial.println();
  Serial.println("Done reading");
  Serial.print("Total errors: ");
  Serial.println(errors);
  Serial.println("--------------------------------");
  Serial.println();
}
Download Source