31 May 2010

Minor Project - external EEPROM management: software

/*
* Project: Minor_Project_I2C_24LC08_eeprom
* Author: Lewis Loflin:
for the original software & other details go to
http://www.sullivan-county.com/ele/arduino_24lc08.htm
* Date: Tuesday 23/02/2010 (Lewis's post)
* Modified: Jane-Maree Howard
* Comments: Jane-Maree is using this as a Minor Project,
with the following differences:
* The Arduino Duemilanove is based on the ATmega328 microcontroller.
* The Fritzing diagram of the circuitry employing this software shows
two 24LC08 serial EEPROM chips in tandem on the same 2-wire interface.
* The software does not use all of the 2048 bytes available,
but it could be modified to do this e.g. to write the word "Arduino"
repeatedly until it fills the available EEPROM space.
* The word "Arduino" has seven characters; by counting the characters,
of your stored message/data, you can arrive at the number of bytes
the external EEPROM will send on request, since 1 byte stores 1 character.
You could retrieve all or part of the stored message/data as desired.
Note the modification to the original.
* Platform: Arduino 18
* Purpose: 24LC08 Demo with the ATMEGA128
This is an 8-pin DIP serial EEPROM.
It will store 1024 bytes. (0x3FF)
It uses I2C or "two wire" interface.
* Operation: On power up or reset the "setup" is executed once,
setting up the hardware and writing the text message "Arduino" to the EEPROM.
Then the "loop" section will run over and over.
Whenever sw0 is pressed the text message "Arduino" is read from the EEPROM
and sent via the serial port to a computer running for example Hyper Terminal.
This demonstrates the use of the Wire.h library,
serial ports, and an external switch tied to an input.
Pin designations for the 24LC08:
Pins 1, 2, 3:
if tied to VCC (5 volts) address = 0x54;
if tied to VSS 0x50.
Only two can be used in a single circuit.
Pin 4 VSS or ground.
Pin 5 SDA or serial data. Tied to Arduino analog pin 4.
Pin 6 SCL or serial clock. Tied to Arduino analog pin 5.
Pin 7 WP or write protect. VCC disables write, VSS enables write.
Pin 8 VCC or +5 volts.
*/

#include Wire.h// specify use of Wire.h library.

byte sw0 = 12; // digital pin for switch connected to ground.
int position_pointer = 0x3f0; // address in 24LC08. Values from 000 hex to 3FF hex.

void setup()
{
pinMode(sw0, INPUT);
digitalWrite(sw0, HIGH); // turn on internal pull up
Wire.begin(); // join i2c bus (address optional for master)
Serial.begin(9600); // setup serial for output

// send test message "Arduino"
Wire.beginTransmission(0x50); // connect to 24LC08 device address
Wire.send(position_pointer); // beginning address within EEPROM (0x3f0)
Wire.send("me");
//Wire.send("Arduino");
Wire.endTransmission();
}//end setup()

void loop()
{
//digitalWrite(sw0, HIGH); // turn on internal pull up
while (digitalRead(sw0) == 1)
{} // wait here until switch is pushed.
Wire.beginTransmission(0x50); // link to 24LC08
Wire.send(position_pointer); // must act as a position pointer
Wire.endTransmission();
Wire.requestFrom(0x50, 5); // request 7 bytes from slave device 24LC08

// below will loop until 5 bytes are received.
while(Wire.available()) // slave may send less than requested
{
byte c = Wire.receive(); // receive a byte as character
Serial.print(c); // print the character
}//while()
Serial.print("\n"); // next line
delay(2000); // wait one second.
}//end loop()


//*****************************************************SEE VERY IMPORTANT COMMENT BELOW

2 comments:

  1. VERY IMPORTANT!!
    In the above codings there are
    #include Wire.h
    statements.
    Around the Wire.h there should be 'less-than' &
    'greater-than' symbols.
    these don't show up in these blog postings..
    ..don't forget them!

    ReplyDelete
  2. Well, it's not working :-(
    & i think i've karked one of my 24LC08 EEPROMs..

    The program IS reading something, & it retrieves the number of bytes specified in the software,
    but it's gobbledegook & i don't know what it says..

    (grump!!)
    (sigh!!)

    ReplyDelete