Pages: [1]   Go Down
Author Topic: External Eeprom - Information  (Read 304 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Sr. Member
****
Karma: 2
Posts: 433
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
#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:
 Wire.write((int)(eeaddress >> 8));   // What are means ?
  Wire.write((int)(eeaddress & 0xFF)); // What are means ?

and this
Code:
 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
 
« Last Edit: February 04, 2013, 10:27:34 am by gnusso » Logged

Global Moderator
Boston area, metrowest
Online Online
Brattain Member
*****
Karma: 538
Posts: 27097
Author of "Arduino for Teens". Available for Design & Build services. Now with Unlimited Eagle board sizes!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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









Logged

Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

Offline Offline
Jr. Member
**
Karma: 0
Posts: 57
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

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

Global Moderator
Boston area, metrowest
Online Online
Brattain Member
*****
Karma: 538
Posts: 27097
Author of "Arduino for Teens". Available for Design & Build services. Now with Unlimited Eagle board sizes!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

That link only  helps for the >> 8 question.
The main question was understanding I2C operation.
Logged

Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

Pages: [1]   Go Up
Jump to: