aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStefan Agner <stefan.agner@toradex.com>2017-03-31 12:50:18 -0700
committerJean Delvare <jdelvare@suse.de>2017-08-10 10:11:15 +0200
commit7c1260bd0ee73c392f8c2a5b32b4b7c118011255 (patch)
tree73686a89bfafc0c5891391ec2ea23ba8a8413741
parentc68f751764800c73206d546f2315e071534e2e13 (diff)
downloadi2c-tools-7c1260bd0ee73c392f8c2a5b32b4b7c118011255.tar.gz
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.
-rw-r--r--CHANGES1
-rw-r--r--eeprog/24cXX.c13
2 files changed, 11 insertions, 3 deletions
diff --git a/CHANGES b/CHANGES
index e6afb07..2cb26dc 100644
--- a/CHANGES
+++ b/CHANGES
@@ -46,6 +46,7 @@ SVN HEAD
decode-vaio: Add a manual page
eeprog: Add a manual page
Moved to a separate subdirectory
+ Increase delay after writes
eeprom: Add a manual page
Marked as deprecated
eepromer: Add a manual page
diff --git a/eeprog/24cXX.c b/eeprog/24cXX.c
index d72f7d0..b21f6b8 100644
--- a/eeprog/24cXX.c
+++ b/eeprog/24cXX.c
@@ -26,6 +26,13 @@
#include <i2c/smbus.h>
#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;
@@ -33,7 +40,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;
}
@@ -44,7 +51,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;
}
@@ -56,7 +63,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;
}