From d4b95a31cdf6098082951d09da58fdb4ccc9403d Mon Sep 17 00:00:00 2001 From: Stefan Agner Date: Fri, 31 Mar 2017 12:50:18 -0700 Subject: [PATCH] eeprog: Increase sleep between byte writes Increese sleep time between writes to accomodate typical write cycle times. An Atmel AT24C02 as well as an ON Semiconductor CAT24C02 EEPROM specify 5ms. This resolves errors such as: ... Bus: /dev/i2c-1, Address: 0x50, Mode: 8bit Writing stdin starting at address 0x0 ..Error i2c_write_2b: Input/output error Error at line 162: write error [JD] Define a single constant and add a note that this could be revisited. --- CHANGES | 1 + eepromer/24cXX.c | 13 ++++++++++--- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/CHANGES b/CHANGES index 792e577..59cbdd2 100644 --- a/CHANGES +++ b/CHANGES @@ -2,6 +2,7 @@ i2c-tools CHANGES ----------------- 3.1.3 (work in progress) + eeprog: Increase delay after writes decode-dimms: Correctly check for out-of-bounds vendor ID README: Mention the current maintainer diff --git a/eepromer/24cXX.c b/eepromer/24cXX.c index c29defd..a7e5a2f 100644 --- a/eepromer/24cXX.c +++ b/eepromer/24cXX.c @@ -24,6 +24,13 @@ #include #include "24cXX.h" +/* + * EEPROMs need some time to process writes + * Ideally this value should either be settable with a command line parameter, + * or "guessed" at runtime using a retry loop. + */ +#define WRITE_DELAY_US 5000 + static int i2c_write_1b(struct eeprom *e, __u8 buf) { int r; @@ -31,7 +38,7 @@ static int i2c_write_1b(struct eeprom *e, __u8 buf) r = i2c_smbus_write_byte(e->fd, buf); if(r < 0) fprintf(stderr, "Error i2c_write_1b: %s\n", strerror(errno)); - usleep(10); + usleep(WRITE_DELAY_US); return r; } @@ -42,7 +49,7 @@ static int i2c_write_2b(struct eeprom *e, __u8 buf[2]) r = i2c_smbus_write_byte_data(e->fd, buf[0], buf[1]); if(r < 0) fprintf(stderr, "Error i2c_write_2b: %s\n", strerror(errno)); - usleep(10); + usleep(WRITE_DELAY_US); return r; } @@ -54,7 +61,7 @@ static int i2c_write_3b(struct eeprom *e, __u8 buf[3]) r = i2c_smbus_write_word_data(e->fd, buf[0], buf[2] << 8 | buf[1]); if(r < 0) fprintf(stderr, "Error i2c_write_3b: %s\n", strerror(errno)); - usleep(10); + usleep(WRITE_DELAY_US); return r; }