Seeeduino XIAO (SAMD21 Cortex M0+) vs EEPROM (m24c04)

Hi all,

I‘ve posted this question on Arduino board too.

Usually I don’t start new posts but read only in forums. But after reading posts and blogs for months I need to ask you for help directly. I’ve developed a huge project (at least for me). Now I need to implement an EEPROM to save data and configurations permanently to finish my project. I’ve setup a tiny code for debugging purpose which has same issues.

I’m using a Seeeduino XIAO on an expansion board and have soldered an external M24C02 EEPROM (TSSOP8 case).

I’ve found the EEPROM’s address with the help of I2Cscanner which is 0x51. Now I’m trying to read its data. But it gives me different values each time I read its bytes.

Hope someone can help me.

#include <Wire.h>     // for I2C
#define EEPROM 0x51    // EEPROM address 
byte data; // data to store in or read from the EEPROM
 
void setup()
{
  Wire.begin();
  Serial.begin(9600);   // initialize serial and wait for port to open:
  while (!Serial) { ; } // wait for serial port to connect. Needed for native USB port only
  Serial.println("Setup done.");
}
 
void loop()
{
  Serial.println("Reading EEPROM...");
  
  for(byte address = 0; address < 10; address++)
  {
    Wire.beginTransmission(EEPROM);
    Wire.write(address);
    Wire.endTransmission(1);
    Wire.requestFrom(EEPROM,1); // get the byte of data
    data = Wire.read();
    Serial.print(address);
    Serial.print(" : ");
    Serial.println(data, BIN);
  }

  Serial.println("DONE\n");
  delay(30000);
}

Output:

Setup done.
Reading EEPROM…
0 : 1000
1 : 110101
2 : 10010
3 : 1011000
4 : 100
5 : 1
6 : 10000
7 : 10000000
8 : 11111001
9 : 11111001
DONE

Reading EEPROM…
0 : 1000
1 : 1110101
2 : 1000010
3 : 1011000
4 : 1000100
5 : 1000001
6 : 1000000
7 : 11000000
8 : 11111001
9 : 11111001
DONE

Reading EEPROM…
0 : 1000
1 : 110101
2 : 10010
3 : 1011001
4 : 100
5 : 1
6 : 10000
7 : 10000000
8 : 11111001
9 : 11111001
DONE

Reading EEPROM…
0 : 1000
1 : 1110101
2 : 1000010
3 : 1011001
4 : 1000100
5 : 1000001
6 : 1000000
7 : 11000000
8 : 11111001
9 : 11111001
DONE

Reading EEPROM…
0 : 1000
1 : 110101
2 : 10010
3 : 0
4 : 101
5 : 1
6 : 10000
7 : 10000000
8 : 11111001
9 : 11111001
DONE

The device at 0x51 is the PCF8563 RTC chip on the expansion board.

For my 24C04, If I wire the A1 and A2 pins of the 24C04 to ground, there will be a conflict, so I must wire A1 and/or A2 to Vcc (3.3 Volts)

For my test I wired my 24C04 A1 to 3.3 Volts and A2 to ground. (See Footnote[1])

This means, Device address 0x52 will be used to access the lower 256 bytes of the EEPROM and device address 0x53 will be used to access the upper 256 bytes.

Here’s information that I included in the comments of my I2C scanner sketch:

/* XAIO I2C Scanner
 * davekw7x
 * March, 2022
 */
// To test persence of an AT24C04 EEPROM, make these connections:
// AT24C04
//  1 (No Connection)
//  2 +3.3V    A1 
//  3 Gnd      A2
//  4 Gnd
//  5 SDA      XIAO D4
//  6 SDC      XIAO D5
//  7 +3.3V
//  8 +3.3V
//
// With XIAO plugged into a Seeed and a '24C04 connected as above, you get the following
//
//  Found device on Wire  at 0x3C (This is the LCD)
//  Found device on Wire  at 0x51 (This is the PCF8563 RTC)
//  Found device on Wire  at 0x52 (Lower 256 Bytes of the '24C04)
//  Found device on Wire  at 0x53 (Upper 256 Bytes of the '24C04)

If this scanner doesn’t show anything other than 0x3C and 0x51, your connections to the EEPROM are wrong (or, your hardware is defective). By the way, don’t use external pull-up resistors on the I2C signals.

Regards,

Dave

Footnotes
[1]
Note that I tested with a 24C04. For your 24C02, you can connect A0, A1, and A2 all to ground to get device address 0x50. You can connect these for any address other than 0x51.

[2]
I didn’t try to analyze your code. If you get the scanner to work but still can’t get EEPROM access, post again and tell us your results.

XIAO_I2C_Scanner.zip (1.1 KB)

You are my hero! Thanks a lot, Dave. Unplugging the expansion board solved my issue. I absolutely forgot about the RTC. Such a simple solution wasted so much time on it. So happy now.

Regards

Setup done.
Reading EEPROM…
0 : 11111111
1 : 11111111
2 : 11111111
3 : 11111111
4 : 11111111
5 : 11111111
6 : 11111111
7 : 11111111
8 : 11111111
9 : 11111111
DONE

Reading EEPROM…
0 : 11111111
1 : 11111111
2 : 11111111
3 : 11111111
4 : 11111111
5 : 11111111
6 : 11111111
7 : 11111111
8 : 11111111
9 : 11111111
DONE