Microchip 24LC256 from Jaycar does not work....why?

I am using the following hookup guide except with all address lines tied to GND and I am using a Mega rather than an Uno.

This is the result from the IC2 scanner sketch:

Scanning...
I2C device found at address 0x50  !
done

This is my code....from the sparkfun library.

/*
  Read and write settings and calibration data to an external I2C EEPROM
  By: Nathan Seidle
  SparkFun Electronics
  Date: December 11th, 2019
  License: This code is public domain but you buy me a beer if you use this
  and we meet someday (Beerware license).
  Feel like supporting our work? Buy a board from SparkFun!
  https://www.sparkfun.com/products/18355

  This example demonstrates how to read and write various variables to memory.

  The I2C EEPROM should have all its ADR pins set to GND (0). This is default
  on the Qwiic board.

  Hardware Connections:
  Plug the SparkFun Qwiic EEPROM to an Uno, Artemis, or other Qwiic equipped board
  Load this sketch
  Open output window at 115200bps
*/

#include <Wire.h>

#include "SparkFun_External_EEPROM.h" // Click here to get the library: http://librarymanager/All#SparkFun_External_EEPROM
ExternalEEPROM myMem;

void setup()
{
  Serial.begin(115200);
  //delay(250); //Often needed for ESP based platforms
  Serial.println("Qwiic EEPROM example");

  Wire.begin();

  //We must set the memory specs. Pick your EEPROM From the list:

  // 24xx00 - 128 bit / 16 bytes - 1 address byte, 1 byte page
  // 24xx01 - 1024 bit / 128 bytes - 1 address byte, 8 byte page
  // 24xx02 - 2048 bit / 256 bytes - 1 address byte, 8 byte page
  // 24xx04 - 4096 bit / 512 bytes - 1 address byte, 16 byte page
  // 24xx08 - 8192 bit / 1024 bytes - 1 address byte, 16 byte page
  // 24xx16 - 16384 bit / 2048 bytes - 1 address byte, 16 byte page
  // 24xx32 - 32768 bit / 4096 bytes - 2 address bytes, 32 byte page
  // 24xx64 - 65536 bit / 8192 bytes - 2 address bytes, 32 byte page
  // 24xx128 - 131072 bit / 16384 bytes - 2 address bytes, 64 byte page
  // 24xx256 - 262144 bit / 32768 bytes - 2 address bytes, 64 byte page
  // 24xx512 - 524288 bit / 65536 bytes - 2 address bytes, 128 byte page
  // 24xx1025 - 1024000 bit / 128000 byte - 2 address byte, 128 byte page
  // 24xxM02 - 2097152 bit / 262144 byte - 2 address bytes, 256 byte page

  // Setting the memory type configures the memory size in bytes, the number of address bytes, and the page size in bytes.

  // Default to the Qwiic 24xx512 EEPROM: https://www.sparkfun.com/products/18355
  myMem.setMemoryType(256); // Valid types: 0, 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1025, 2048
  myMem.setPageWriteTime(5);
  myMem.setMemorySizeBytes(32768);

  if (myMem.begin() == false)
  {
    Serial.println("No memory detected. Freezing.");
    while (true)
      ;
  }
  Serial.println("Memory detected!");

  Serial.print("Mem size in bytes: ");
  Serial.println(myMem.length());

  //Yes you can read and write bytes, but you shouldn't!
  byte myValue1 = 200;
  myMem.write(0, myValue1); //(location, data)

  byte myRead1 = myMem.read(0);
  Serial.print("I read (should be 200): ");
  Serial.println(myRead1);

  //You should use gets and puts. This will automatically and correctly arrange
  //the bytes for larger variable types.
  int myValue2 = -366;
  myMem.put(10, myValue2); //(location, data)
  int myRead2;
  myMem.get(10, myRead2); //location to read, thing to put data into
  Serial.print("I read (should be -366): ");
  Serial.println(myRead2);

  float myValue3 = -7.35;
  myMem.put(20, myValue3); //(location, data)
  float myRead3;
  myMem.get(20, myRead3); //location to read, thing to put data into
  Serial.print("I read (should be -7.35): ");
  Serial.println(myRead3);

  String myString = "Hi, I am just a simple test string";
  unsigned long nextEEPROMLocation = myMem.putString(30, myString);
  String myRead4 = "";
  myMem.getString(30, myRead4);
  Serial.print("I read: ");
  Serial.println(myRead4);
  Serial.print("Next available EEPROM location: ");
  Serial.println(nextEEPROMLocation);
}

void loop()
{
}

But this is the output:

Qwiic EEPROM example
Memory detected!
Mem size in bytes: 32768
I read (should be 200): 0
I read (should be -366): 0
I read (should be -7.35): 0.00
I read: 
Next available EEPROM location: 65

Is there a bug in the wire library atm?

I see that you don't pick one of the options, not even the default option. In this section of code you need to choose one of them by un commenting the appropriate line.

This has been edited from the exapmle and is how the correct chip is specified.

a7

It does not seem to matter what I do or what library I use, the chip just does not work.

  myMem.setMemoryType(256);
  myMem.setMemorySizeBytes(32768); //This function will set the AddressBytes and PageSize.
  myMem.setAddressBytes(2); //Call these functions after MemorySizeBytes. Only needed if you have a very unique EEPROM with odd Address Bytes and Page Sizes.
  myMem.setPageSizeBytes(64);
  myMem.setPageWriteTime(5);

It can happen. You seem to be using example code and to have configured it for that chip.

Scanning success shows it is at the zero position of 0x50 the bottom of the chio's range, leaving only the pull-ups as a matter.

I don't know that a successful scan will ensure proper operations. What value are you using, and does the Mega have any of its own?

a7

This is my actual setup...
I have tried with and without the pull up resistor on the CLK pin.

Either there is a bug in the wire library or else Jaycar has a bunch if fake or faulty chips.

I can't see anything I have done wrong with the wiring.

What value are those pull-up resistors? They don't look like 4.7K.

I would place no money on there being a bug in the wire library. At this time it's like cleaning you've found a compiler probelm like "is the if statement broken ATM?".

a7

.1µF decoupling cap not seen across Vcc-GND.  Don't know it's mandatory for this chip but it's standard for other digital chips.  What could it hurt to try one?

1 Like

How about a test?

Mega 2650 R3
24LC256
4.7K pull-up resistors
0.1uF bypass cap
Sparkfun External EEPROM library
Your sketch.

Results:

Connecting to /dev/ttyACM0. Press CTRL-C to exit.
Qwiic EEPROM example
Memory detected!
Mem size in bytes: 32768
I read (should be 200): 200
I read (should be -366): -366
I read (should be -7.35): -7.35
I read: Hi, I am just a simple test string
Next available EEPROM location: 65

The library appears to be fine. The sketch appears to be fine.

I'd be looking at wiring problems or incorrect pullups. And only if those check out would I consider a bad EEPROM.

1 Like

Look like 10K 1% Brown, Black, Black, Brown, Black

Tom... :smiley: :+1: :coffee: :australia:

How many boards do you stacked on top of the Mega?
Is WP actually grounded?

I don't think there is a black tolerance band. And I think your reading would be 100 * 10¹ = 1K?

It's hard to get the colours correct against those blue backgrounds. But I think I see brown, black, black, red, brown, which would be 100 * 10² = 10K 1%.

But which of the 2 brown bands is the tolerance?

Read in the opposite direction, it could be 120 * 10¹ = 1.2K

Hi, @van_der_decken

Do you have a DMM? (Digital MultiMeter).

If it was a 6 band the black would be a temp co-eff.
Yes it could be a 1K, in this case I'd measure it.

1K2 is also a possibility, the band spacing is not exactly good.

Tom... :smiley: :+1: :coffee: :australia:

I guess both values would work...
What happened to the old days when we had a golden band? Never any reason to doubt in which direction to read the bands...

We've lost it, my precious...

4 Likes

I think you replied to the wrong person there. I was the one asking about the resistors the OP was using.

With a 4th black band, isn't that 120 ohms? A black multiplier is 10^0, not 10^1.

1 Like

Ha! You got revenge for @TomGeorge :wink: You are of course quite correct.

I imagine we all think they're likely 10K, but a quick check with a meter would confirm or refute it. Mind you, the OP has been battling with their Mega and EEPROM problem for a month and a half now, so I'm not hopeful for any quick resolution.