buy hot The Fixer cool video Year One download Kasabian album nice Terminator Salvation hit cool track Jordin Sparks USA Whatever Works video download Check My Brain melodies nice video Finding Nemo nice Pop - Various Artists hit cheap DIVX Year One

digital-diy.com

Swordfish Tutorial/Library - External EEPROM Print E-mail
( 0 Votes )
  
Saturday, 04 April 2009 08:36
24LC2561


External EEPROMS are great for storing data, and to interface with them is not all that hard. Most use the I2C protocol. In this example the 24LC256 is used. I2C communication is great as it can allow serial data communication between many devices on a single 2 wire bus. These two lines are referred too as SDA and SCL. Basically SDA is the serial data and SCL maintains the clock/frequency in which data is transferred.


Like most peripherals, I've made my own Swordfish Library for the 24LC series EEPROM's. Pins 1, 2, 3 set the address of the EEPROM. As you can see in the diagram below, the highest 24LC256 has one connection to earth (Pin 3), and two connections to 5V (Pins 1 & 2).. this defines it as %011 (don't forget that binary starts from the right!) on the I2C Bus.

 

ExtEEPROM1

Pin 8 on 24LC256 = Vdd (5V)

Pin 4 on 24LC256 = Vss (Earth)

Note the PIC's power supply/oscillator are not shown

 

Here is an example of how to use the Library with a single EEPROM (24LC256)

 

Device = 18F452
Clock = 20
// import libraries...
Include "ExtEEPROM.bas"
Include "usart.bas"
Include "Convert.bas"
Dim
    Variable As Byte,       // Variable used for data
    Device_Address As Byte, // Register for I2C Address reference
    Memory_Address As Byte, // Register for EEPROM memory address
    Family As Byte          // Register for External EEPROM family setting
 
    USART.SetBaudrate(br19200)
 
    Variable = 123          // Place the value "1" in the variable register
    Device_Address = %000   // Set the EEPROM I2C address
    Memory_Address = 10     // Set the EEPROM address location to 0
    Family = %1010          // Set the Family configeration as the binary number 1010
    // Write the value 123 to EEPROM 000 at memory location 10
    ExtEEPROM.Write(Variable, Memory_Address, Device_Address, Family)        
    // Read from EEPROM 000, memory location 10
    Variable = ExtEEPROM.Read(Memory_Address, Device_Address, Family)
 
    USART.Write(Convert.DecToStr(Variable))
 
    While True
    Wend

 


Video Tutorials:

Single External EEPROM

Explores the use of the External EEPROM Library

Covers the "Family" register use for compatibility with other EEPROM's

** Note - I mention that 10mS is required after an EEPROM write, this is now part of the Library and is not required **

 

Multiple (4) External EEPROM's

Covers the use of addressing multiple EEPROM's on the I2C Bus with the Library


Download the library: External EEPROM

 

Comments (6)
  • HeX  - Thank you!

    very good tutorials you do!
    Can you talk more about EEPROM. How can i sore and protect data in there.

    And how to work with the Virtual Terminal,
    i see only Gibrish in the prompt window.

    And what about the I2C Protocol Analyzer, what the meaning of all the strange chars???
    http://img146.imageshack.us/img146/1377/proteus.jpg

  • HeX  - Image

    http://img146.imageshack.us/img146/1377/proteus.jpg
    http://img146.imageshack.us/img146/1377/proteus.jpg

  • Graham

    Hi Hex,

    These EEPROM modules are basically external storage devices similar to those that are built-in on the PIC.

    By using these low cost chips you can greatly expand the long term storage capability for projects with any form of data logging.

    The devices used above run on the I2C protocol to allow over 100 devices to be connected on the same bus, handy. With this in mind you wouldn't take that route when SD Memory Cards would be a serious alternative of such large memory requirements (both cost and size).

    The swordfish libraries provide quick and simple addressing of each device on the I2C bus.

    I haven't found myself using the I2C Analyzer as yet, so I can't offer any info sorry :)

  • King Snake  - Thanks!

    Thanks for your help. These Tutorials are great.

    Does anyone know how to use this library to write and read words instead of bytes?

  • Anonymous

    You could use the library as is, and make a simple sub routine that uses modifiers. For example;

    Dim MyWord as word
    DIm LByte , HByte as Byte
    |
    |
    LByte = MyWord.byte0
    HByte = MyWord.byte1

    You can do it by declaration alias as well;

    Dim MyWord as word
    Dim LByte as MyWord.byte0,
    HByte as MyWord.byte1

  • King Snake

    Awesome!
    Thanks, I knew there was an easy way to do it in swordfish. I'm still getting the hang of working around the language.

    I believe I will be removing the delay from the Library though. I will be writing to 8 EEPROMS rapid fire. As I understand it, as long as there is 10ms from writes to the same EEPROM, I should be good. Sound correct?

Write comment
Your Contact Details:
Comment:
[b] [i] [u] [url] [quote] [code] [img]   
Security
Please input the anti-spam code that you can read in the image.
Last Updated ( Friday, 24 April 2009 09:48 )
 

Whos Online

  • dha
  • ta1dr
  • Jon Chandler

Forum Activity