Browse Source

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.
tags/v4.0
Stefan Agner 8 years ago
committed by Jean Delvare
parent
commit
7c1260bd0e
  1. 1
      CHANGES
  2. 13
      eeprog/24cXX.c

1
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

13
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;
}

Loading…
Cancel
Save