سؤال

I'm trying to write into an EEPROM via I²C from user space. I'm using the /dev device file and the open, read, write and ioctl functions. Reading works without a problem, but when I use the same code for writing (just replacing read with write), it fails. The EEPROM is not write protected (echoing into the device file of the EEPROM driver works).

The code I have is as follows.

if ((fd = open(write_destination, O_RDWR)) < 0) {
    goto error;
}

if (ioctl(fd, I2C_SLAVE_FORCE, 0x50) < 0) {
    goto error_fd;
}
while((n = write(fd, self->fields[i].buf, self->fields[i].size)) != self->fields[i].size) 
    perror("");

What am I overlooking?

هل كانت مفيدة؟

المحلول

Some EEPROMs only allow writing small amounts, then wait, and then write more. Check the datasheet to be sure. Also, I recommend to use a logic analyzer to check the correct commands are going to the I²C - I love the analyzer at www.salae.com.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top