Skip to content

More than 32 bytes cannot be written via I2C #246

Closed
@arcao

Description

@arcao

When I try to write more than 32 bytes (2B for address + >30B data) via I2C to AT24C256 EEPROM device, next written byte is NAKed. I guess it's because a new transaction is started and EEPROM device thinks that is a new (PAGE) WRITE command. AT24C256 supports up to 64 bytes to be transferred with that command.

i2c-64b-error

Note: Between PAGE WRITE and any other command has to be a delay (max 5ms by datasheet) to be data physically written, so this is the reason of NAK.

Test code:

#include <Arduino.h>
#include <Wire.h>

#define PIN_SDA  21  // I2C SDA
#define PIN_SCL  22  // I2C SCL

void setup() {
  int i2cdevice = 0x50;  // 24C256 EEPROM address with A0=0, A1=0, A2=0
  int addr;
  int res;

  Serial.begin(115200);
  Serial.println("Initializing I2C");
  Wire.begin(PIN_SDA, PIN_SCL);

  addr = 0;

  Wire.beginTransmission(i2cdevice);
  Wire.write(addr >> 8);
  Wire.write(addr & 0xff);
  
  for (uint8_t i = 1; i <= 64; i++) {
    Wire.write(i);
  }
  res = Wire.endTransmission();
  if (res != 0) {
    Serial.println("Write error!");
  }

}

void loop() {}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions