BREAKING NEWS

19 April 2016

Use Library Wire Arduino with I2C EEPROM 24AA1025

We made many guides for beginners with this guide we will begin to realize more and more articulated guides. In a previous article, we explained how to use the library Wire I2C Arduino with all its various functions and logic to use it.(We recommend that you read the previous article to understand each step that will be discussed). In this guide, we will explain how to use it. For starters, we explain to readers that can be replicated with the left vast majority of EEPROM memories in the market. We have chosen a memory to 1024K for higher data capacity. The integrated we are going to use and that you will find in our shop is called EEPROM 24aa1025.

LIST OF MATERIALS:
  • Arduino Uno
  • EEPROM 24aa1025
  • breadboard
  • Jumper Male
Why use an additional EEPROM memory?

The question can be answered simply thinking about the limited memory of our Arduino microcontroller, a limit that can be easily overcome with the addition of more EEPROM memories that you can manage with a single Arduino thanks to the Wire library, which allows, by means of pin 2 only make a SLAVE MASTER system and be able to manage multiple memories.


Pins A0, A1, A2 enable you to specify the address of the device on the I2C bus, the pins Vcc and Vss are respectively the power supply (5VDC) and ground (GND), the pin WP (Write Protect) enables (if connected to Gnd) or disables (if connected to Vcc) the writing of the EEPROM, the pins SCL and SDA reflect their I2C link.
As we have said previously, we used the integrated EEPROM 24aa1025. This memory we can easily connect to our Arduino UNO Through Pin I2C Bus:
  • A4 SDA
  • A5 SCL
We see an image to make the idea of the various links between memory and the Arduino:

The connections are pretty simple as using complex. As we can see in this case, we have three memory pin A0 A1 A2 which are grounded for a very specific reason. These pins allow you to customize the device address on the I2C bus, so we can use more EEPROM memories simultaneously. While each manufacturer would have the same memory address, we will be the problem of duplicate addresses. Instead of having 3 bits manageable we can give them a high-low value and have the possibility of n combinations of addresses to be used so the higher number of EEPROM.



We see in the image that the C ontrol Code from datasheets of our memory is set to 1 0 1 0 then the four most significant bits are preset. While bits A0, A1, and A2 can be customized by us. The least significant bit R / W, is used to select a write operation or a read operation.
The core having grounded the pins A0, A1 and A2 we will be a low value and then all set to zero. The address of the device is therefore as follows: 1010000
Since we are programming with Arduino by convention we go to convert to hex the address value of the binary slave EEPROM memory.
1010000 in hexadecimal corresponds to 0x50
The memory  24AA1025  owns 1024Kbit memory, so the memory locations that we can write and read are  128000 bytes (1024000/8). 
With the availability of 2 bytes to select the address ( Address High Byte and Low Byte Address ) we can use a variable int (precisely formed by 2 bytes) that would take us to specify the address value of the memory location (0 to 127 999).
The Wire library still does not allow to pass an integer value so we could just make a bitwise operation divide the integer variable into two bytes. Fortunately, there are already functions that simplify this operation, high byte, and low byte.
Let's see the code what we will do and write the first 1200 memory locations and via the serial going to re-read the various values obtained:

#include <Wire.h>
 
address int = 0;
int date = 0;
int loop = 0;
 
void setup ()
{
  Serial.begin (9600);
  // We expect the serial
  while (! Serial)
  {
    ;
  }
  delay (5000);
  // Send a message to the serial monitor
  Serial.println ( "Start");
 
  // Initialize the I2C port of the Arduino
  Wire.begin ();
}
 
void loop ()
{
  // Notice of the commencement of the
  // Write to the serial data
  Serial.println ( "Start Writing");
 
  // Init variable
  address = 0;
 
  // Run cyclically writing
  // 1200 memory locations



  for (loop = 0; loop <1200; loop ++)
  {
    // Send the control byte specifying
    // A write request
    Wire.beginTransmission (0x50);
 
    // Send two bytes containing the address of the
    // Memory location you want to write a byte
    Wire.write (high byte (address));
    Wire.write (low byte (address));
 
    // Write one byte in the memory location
    // Previously selected
    Wire.write (bytes (data));
    // End of transmission
    Wire.endTransmission ();
 
    // Increment the date value
    date ++;
 
    // If the date variable reaches 255
    // It resets its value to zero
    if (data == 255)
      date = 0;
 
    // Increment the address value
    address ++;
 
    // Wait 5ms to terminate the operations of
    // Writing on memory
    delay (5);
  }
 
  // Email me when writing 1200 bytes
  // Is finished
  Serial.println ( "End of Scripture");
 
  // Wait 1/2 second
  delay (500);
 
  // Alert me of the beginning of the reading
  Serial.println ( "Start reading");
 
  // Init variable
  address = 0;
 
  for (loop = 0; loop <1200; loop ++)
  {
    // Send the control byte specifying
    // A write request
    Wire.beginTransmission (0x50);
 
    // Sending two bytes to select the location
    // Memory Read
    Wire.write (high byte (address));
    Wire.write (low byte (address));
 
    Wire.endTransmission ();
 
    // Increment the address variable
    address ++;
 
    // I request a byte to 24AA1025
    Wire.requestFrom (0x50, 1);
    // Look forward to the availability of data on i2c bus
    while (Wire.available ())
    {
      Serial.print (cycle);
      Serial.print ( ":");
 
      // I read from the figure for the bus
      // Previously specified memory location
      bytes Wire.read c = ();
 
      // Send the data to the serial monitor
      Serial.println (c);
   }
 }
 
 delay (1000);
}

Share this:

1 comment :

  1. Several Errors. No pull up resistors, Microchip data sheet states 10K for 100 kHz and 2K for 400kHz. Error 2, Microchip states that A2 MUST BE tied to Vcc! So if the code below was tested with the configuration shown and works, they should be notified to correct their data sheet.

    ReplyDelete

 
Back To Top
Distributed By Blogger Templates | Designed By OddThemes