Go Down

Topic: External Eeprom - Information (Read 371 times) previous topic - next topic

gnusso

Feb 04, 2013, 02:57 pm Last Edit: Feb 04, 2013, 04:27 pm by gnusso Reason: 1
Good Afternoon,
for my project i was thinking to implement external eeprom instead of arduino eeprom because I have at disposition 1.000.000 of write cycle instead of 100.000.

then before to write a post (how ever I've tried to look inside google) and I've found this: topic
http://www.hobbytronics.co.uk/arduino-external-eeprom

Code: [Select]

#include <Wire.h>   

#define disk1 0x50    //Address of 24LC256 eeprom chip

void setup(void)
{
  Serial.begin(9600);
  Wire.begin(); 

  unsigned int address = 0;

  writeEEPROM(disk1, address, 123);  // eeprom is at the 0x50, add of memory 0 and data 123
  Serial.print(readEEPROM(disk1, address), DEC);
}

void loop(){}

void writeEEPROM(int deviceaddress, unsigned int eeaddress, byte data )
{
  Wire.beginTransmission(deviceaddress);
  Wire.write((int)(eeaddress >> 8));   // MSB
  Wire.write((int)(eeaddress & 0xFF)); // LSB
  Wire.write(data);
  Wire.endTransmission();

  delay(5);
}

byte readEEPROM(int deviceaddress, unsigned int eeaddress )
{
  byte rdata = 0xFF;

  Wire.beginTransmission(deviceaddress);
  Wire.write((int)(eeaddress >> 8));   // MSB
  Wire.write((int)(eeaddress & 0xFF)); // LSB
  Wire.endTransmission();

  Wire.requestFrom(deviceaddress,1);

  if (Wire.available()) rdata = Wire.read();

  return rdata;
}


This line of code what are means ?:

Code: [Select]

 Wire.write((int)(eeaddress >> 8));   // What are means ?
 Wire.write((int)(eeaddress & 0xFF)); // What are means ?


and this
Code: [Select]

 Wire.write((int)(eeaddress >> 8));   //   What are means ?
 Wire.write((int)(eeaddress & 0xFF)); // What are means ?

 Wire.requestFrom(deviceaddress,1);  //What are means ?




Looking the example is not more easy like write and read Arduino Eeprom ... so my question is:

Is there some library that I can use in order to use "external eeprom" easily as "arduino eeprom" ?

Thanks 10000 for support,
Gnux

CrossRoads

External EEPROM is typically accessed via an SPI or I2C interface. Your example appears to be using I2C interface:  #include <Wire.h>
Both send out addresses and data as 8-bit numbers (a byte).

This a 16 bit address
 unsigned int address = 0;

This breaks it up into 2 bytes and sends it out:

Wire.write((int)(eeaddress >> 8 ));   //   If the address was 0x1234, this shifts the 12 over 8 bit positions and sends it out
 Wire.write((int)(eeaddress & 0xFF)); // This masks off the 12, so that only 34 is left and sends it out.

Another way to perform this would be:
Wire.write((int)(highByte(eeaddress));
Wire.write((int)(lowByte(eeaddress));

This is setting up the address that will be read from.

This tells the device to send 1 byte.  deviceaddress will be the EEPROMs I2C bus address; typically the lowest bit of the address will be 0 or 1 to tell the device a read or write is occurring;
 Wire.requestFrom(deviceaddress,1);  //What are means ?

 Wire.write(data);  will send data to the device

Wire.read();  will read the data the device sends









Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.

eriknyquist

this link will help you understand what's going on here;

http://www.cprogramming.com/tutorial/bitwise_operators.html

CrossRoads

That link only  helps for the >> 8 question.
The main question was understanding I2C operation.
Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy