External EEPROM Recording

j4e8a16n
Posts: 9
Joined: Mon Nov 18, 2019 5:55 pm

External EEPROM Recording

Postby j4e8a16n » Tue Nov 26, 2019 6:43 pm

Code: Select all

/*
  External EEPROM Recording
  //Uses AT24LC256 External I2C EEPROM
  DroneBot Workshop 2019

  Uses AT24C256 EEPROM Memory Module 8P Chip 
  Carrier Power Supply Indicator
https://www.cafr.ebay.ca/itm/4Pcs-AT24C256-EEPROM-Memory-Module-8P-Chip-Carrier-Power-Supply-Indicator/162937327097?ssPageName=STRK%3AMEBIDX%3AIT&_trksid=p2057872.m2749.l2649
*/

// Include the I2C Wire Library
#include "Wire.h"

// EEPROM I2C Address
#define EEPROM_I2C_START_ADDRESS 0x7B0C  //31500

// Integer to hold number of addresses to fill
int maxaddress = 32100; //32K  bytes?

// Byte to hold data read from EEPROM
int readVal = 0;

//-----------------------------
void setup()
{
  // Connect to I2C bus as master
  Wire.begin();

  // Setup Serial Monitor
  Serial.begin(9600);

  writEr();

  readEr();
}
// Function to write to EEPROOM
void writeEEPROM(int address, byte val, int i2c_address)
{
  // Begin transmission to I2C EEPROM
  Wire.beginTransmission(i2c_address);

  // Send memory address as two 8-bit bytes
  Wire.write((int)(address >> 8));   // MSB
  Wire.write((int)(address & 0xFF)); // LSB

  // Send data to be stored
  Wire.write(val);

  // End the transmission
  Wire.endTransmission();

  // Add 5ms delay for EEPROM
  delay(5);
}

// Function to read from EEPROM
byte readEEPROM(int address, int i2c_address)
{
  // Define byte for received data
  byte rcvData = 0xFF;

  // Begin transmission to I2C EEPROM
  Wire.beginTransmission(i2c_address);

  // Send memory address as two 8-bit bytes
  Wire.write((int)(address >> 8));   // MSB
  Wire.write((int)(address & 0xFF)); // LSB

  // End the transmission
  Wire.endTransmission();

  // Request one byte of data at current memory address
  Wire.requestFrom(i2c_address, 1);

  // Read the data and assign to variable
  rcvData =  Wire.read();

  // Return the data as function output
  return rcvData;
}

void readEr() {
  int address = EEPROM_I2C_START_ADDRESS;
  // Run until maximum address is reached

  for (; address <= maxaddress; address++) {

    // Read value from EEPROM
    readVal = readEEPROM(address, EEPROM_I2C_START_ADDRESS);

    // Print to Serial Monitor
    Serial.print("From AT24C256 = ");
    Serial.print(address);
    Serial.print("\t");
    Serial.println(readVal);

  }

  // Print to Serial Monitor
  Serial.println("Playback Finished!");
}

void writEr() {
  int address = EEPROM_I2C_START_ADDRESS;

  // Print to Serial Monitor
  Serial.println("Start Recording...");
  // Run until maximum address is reached

  for (; address <= maxaddress; address++) {
    byte val = (address/1000);
    // Record the position in the external EEPROM
    writeEEPROM(address, val, EEPROM_I2C_START_ADDRESS);

    // Print to Serial Monitor
    Serial.print("To AT24C256 = ");
    Serial.print(address);
    Serial.print("\t");
    Serial.println((address/1000));
  }

  // Print to Serial Monitor
  Serial.println("Recording Finished!");
}

void loop()
{

}

Hi to everyone,

I am tryimg to wtite to an external I2C EEPROM. EEPROM Memory Module LC-AT24C256 I2C Development Module for Arduino

I am using a code that I strip off a part.


The reading part of the code is returning 255 for each ddress of the eeprom chip AT24C256. (see attachtment)
https://www.cafr.ebay.ca/itm/4Pcs-AT24C ... 2749.l2649

The value of the adresses should be the address divided by 1000. They are all 255

Here is the output :

Code: Select all

Start Recording...
To AT24C256 = 31500	31
To AT24C256 = 31501	31
To AT24C256 = 31502	31
etc
Recording Finished!

Start reading
From AT24C256 = 31500	255
From AT24C256 = 31501	255
From AT24C256 = 31502	255
From AT24C256 = 31503	255
From AT24C256 = 31504	255
etc
Regards,


JPDaviau
Attachments
AT24C256.pdf
(362.27 KiB) Downloaded 594 times
output.txt
(29.99 KiB) Downloaded 602 times
20191126_123514.jpg
20191126_123514.jpg (2.71 MiB) Viewed 7704 times
Arduino 1.8.10; Windows 10; ESP32 VROOM

Who is online

Users browsing this forum: No registered users and 129 guests