Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More than 32 bytes cannot be written via I2C #246

Closed
arcao opened this issue Mar 3, 2017 · 6 comments
Closed

More than 32 bytes cannot be written via I2C #246

arcao opened this issue Mar 3, 2017 · 6 comments

Comments

@arcao
Copy link
Contributor

arcao commented Mar 3, 2017

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() {}
@me-no-dev
Copy link
Member

@arcao if you have time, you can try to play with the i2c code here and see if not sending the address again on the second iteration of the loop will help you.

@arcao
Copy link
Contributor Author

arcao commented Mar 5, 2017

I will try it later today. I'm not at home just now.

@kriswiner
Copy link

The 32 byte limit is a common hard coded limit used in the Wire library. You can change this in the Wire.h library somewhere but I usually just accept this and buffer data writes in 32 byte chunks to keep the code platform agnostic.

@lonerzzz
Copy link
Contributor

@me-no-dev @kriswiner Does it make sense to add an API to set the Wire library to change the byte limit from a set default? Is there any known implementation where this has been done before?

@kriswiner
Copy link

kriswiner commented Aug 25, 2017 via email

@copercini
Copy link
Contributor

copercini commented Sep 21, 2018

Fixed with I2C RC1

darkxst pushed a commit to darkxst/arduino-esp32 that referenced this issue Dec 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants