Your new topic does not fit any of the above??? Check first. Then post here. Thanks.

Moderator: igrr

User avatar
By YV1HX
#58537 Hello there, This is my very first post here.

Using a nodeMCU, I'm trying to read and write an 24C08 I2C EEPROM, seems to be correctly wired, since the Nick Gammon's I2C Scanner detects the device and the neighbor DS1307 connected to the same bus.

The circuit have two 4K7 Ohm pull-up resistors connected to the 3V3 source available at some nodeMCU pins.

The scanner reports 5 devices (see attached image):

0x68, (the DS1307 RTC), and four devices (?) ranging from 0x50 to 0x53, the weird thing is the fact 24C08 EEPROM is supposed to answer only at the 0x50 address (all Address pins connected to GND, also the pin 7, Write Protect is connected to +5V).

ScannerOutput.png


I can control and use without problems the RTC; both DS1307 & the 24C08 are connected to the same +5V supply, so the wiring should be correctly cabled.

When trying to write/read to/from the EEPROM, I never get the value that I suppose to be writing, the sketch always return "255"; tried to change the "base address" from 0x50 to 0x53 with the same results.

ProgramOutput.png


I have used this code before successfully in a Arduino Nano circuit, but using 24LC256 and a couple of AT24C1024B EEPROMS.

Any advice will be great.

Thanks in advance.
Code: Select all/////////////////////////////////////////////////////////////////////////////////////////
// General include
#include <Wire.h>
#include <EEPROM.h>
/////////////////////////////////////////////////////////////////////////////////////////
// EEPROM definitions
unsigned int EEPROMBank = 0x50;                 // Base address of 1st EEPROM chip
unsigned int EEPROMAddress = 0;                 // Sets the start EEPROM address
unsigned int EEPROMValue = 0;                   // EEPROM value
byte Dummy;
// EEPROM list taken from:
// http://vascoferraz.com/projects/24c-eeprom-check/
// Sets the Maximum EEPROM address, uncomment accordingly:
//#define MaxBankAddress = 128 - 1;             //24C01    -> 1024 bit    -> 128 byte
//#define MaxBankAddress = 256 - 1;             //24C02    -> 2048 bit    -> 256 byte
//#define MaxBankAddress = 512 - 1;             //24C04    -> 4096 bit    -> 512 byte
unsigned int MaxBankAddress = 1024 - 1;         //24C08    -> 8192 bit    -> 1024 byte
//#define MaxBankAddress = 2048 - 1;            //24C16    -> 16384 bit   -> 2048 byte
//#define MaxBankAddress = 4096 - 1;            //24C32    -> 32768 bit   -> 4096 byte
//#define MaxBankAddress = 8192 - 1;            //24C64    -> 65536 bit   -> 8192 byte
//#define MaxBankAddress = 16384 - 1;           //24C128   -> 131072 bit  -> 16384 byte
//#define MaxBankAddress = 32768 - 1;           //24C256   -> 262144 bit  -> 32768 byte
//#define unsigned int maxaddress = 65536 - 1;  //24C512   -> 524288 bit  -> 65536 byte
/////////////////////////////////////////////////////////////////////////////////////////
// I2C definitions
#define SCLPin D1                               // I2C SCL Pin
#define SDAPin D2                               // I2C SDA Pin
/////////////////////////////////////////////////////////////////////////////////////////
// RTC DS1307 definitions
/////////////////////////////////////////////////////////////////////////////////////////
void setup() {
  // Wire.begin();                              // Initialize 2-Wire bus
  // http://www.esp8266.com/viewtopic.php?f=13&t=10374#p49060
  // Wire.begin(int sda, int scl);              // Initialize 2-Wire bus
  Wire.begin(SDAPin, SCLPin);                   // Initialize 2-Wire bus
  pinMode(D1, INPUT_PULLUP);                    // I Need to validate this line
  pinMode(D2, INPUT_PULLUP);                    // I Need to validate this line
  Serial.begin(19200);                          // Initialize serial port
  while(!Serial);                               // wait for serial
  delay(3000);                                  // Waits 3 seconds
  Serial.println("\n=============================");          // Sends preamble and Cr+Lf
  EEPROMAddress = 0;                            // EEPROM word variable
  EEPROMValue = 123;                            // EEPROM value
  Serial.print("EEPROMAddress: ");
  Serial.print(EEPROMAddress);
  Serial.print(", EEPROMValue: ");
  Serial.print(EEPROMValue);
  Serial.print(", EEPROMBank: 0x");
  Serial.println(EEPROMBank,HEX);
  writeEEPROM(EEPROMBank, EEPROMAddress, byte(EEPROMValue));
  for (EEPROMAddress = 0; EEPROMAddress < 3; EEPROMAddress++) {
     Serial.print("EEPROMAddress: ");
     Serial.print(EEPROMAddress);
     Serial.print(", Value: ");
     Serial.println(readEEPROM(EEPROMBank, EEPROMAddress), DEC);
  }
}
/////////////////////////////////////////////////////////////////////////////////////////
void loop(){
  // Do something useful here.
}
///////////////////////////////////////////////////////////////////////////////////////////
// http://www.hobbytronics.co.uk/arduino-external-eeprom
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;
}
/////////////////////////////////////////////////////////////////////////////////////////
You do not have the required permissions to view the files attached to this post.
User avatar
By piersfinlayson
#58614 I'd get a logic analyser on it, check that you are actually sending to the device what you think you are, and I'd also explicitly put an ack polling loop in to confirm when the device claims to have written the data. If you get an ack immediately after writing then it hasn't been written for some reason - I found it took around 18 iterations around a tight loop writing the read address before the device responded with an ack.

I did some playing with the 24aa00, and have some 24lc128s on their way to use in production. I didn't use the Arduino library - I worked directly with the SDK on top of brzo_i2c.

Edit: Meant to link to: http://www.packom.org/esp8266/mcp/24aa00/i2c/2016/10/01/mcp-24aa00-family.html
Last edited by piersfinlayson on Thu Nov 24, 2016 8:03 am, edited 1 time in total.
User avatar
By trackerj
#58615 I have used a similar setup with a DS3231 RTC Module that has a onboard a 24C32 EEPROM:

Image

Even not been Arduino IDE code below, might help you a lot as wiring I2C, read/write operations been explained:
AT24C32 - I2C External EEPROM Data Looger
User avatar
By martinayotte
#58619 All the 24C02/04/08/16 chips are not following the same addressing scheme than bigger chips such 24C64.
It is normal that 24C08 respond for times to scanner since it provide 4 page of 256 bytes.
The library you are using probably doesn't handle those small chips because it is providing 16 bits addressing instead of 8 bits.
I would then suggest to unsolder this 24C16 and throw it away and solder a bigger one such 24C64 or even bigger, since those so cheap on eBay.