0

Arch Linux を使用して Cubieboard 2 の i2c 経由で AT24MAC402 EEPROM を読み書きしようとしています。i2c-dev ライブラリと i2c-tools を使用しています。

データシート: http://www.atmel.com/images/atmel-8807-seeprom-at24mac402-602-datasheet.pdf

選択したアドレスに (一種の...) 正常に書き込み、そのアドレスから始まる多くのバイトを順番に書き込むことができます。問題は次のとおりです。

  1. 最初のアドレスが選択されると、別のアドレスを選択して書き込むことはできません。
  2. EEPROM を (ダミー書き込みによって) 読み取りたい場所に向けることができないため、EEPROM を実際に制御することはほとんどできません。

データシートを (何時間も続けて) 見ると、i2c-dev ライブラリを使用する必要があるほど I2C 通信を制御できていないように見えます。ビットまたは X バイトを直接 EEPROM に転送します。

一言で言えば、この EEPROM を適切に読み書きする方法についてアドバイスをお願いします。

    char buf[10];

    int com_serial;
    int failcount;

    int i2c_init(char filename[40], int addr)
        {
        int file;

        if ((file = open(filename,O_RDWR)) < 0)
                {
                printf("Failed to open the bus.");
                /* ERROR HANDLING; you can check errno to see what went wrong */
                com_serial=0;
                exit(1);
                }

    if (ioctl(file,I2C_SLAVE,addr) < 0)
                {
                printf("Failed to acquire bus access and/or talk to slave.\n");
                /* ERROR HANDLING; you can check errno to see what went wrong */
                com_serial=0;
                exit(1);
                }
        return file;
        }


    int main (int argc, char *argv[]) { 

    char read_buf[16];
    char write_buf[17];
    int i;

    int file;
    file=i2c_init("/dev/i2c-1",0x50); //dev,slavei2caddr
    write_buf[0] = 0x00;
    write_buf[1] = 'H';
    write_buf[2] = 'i';
    write_buf[3] = '!';
    write(file, write_buf, 4);
    //Successfully prints "Hi!" to bytes 0x00 -> 0x02

    //Setting EEPROM to point to address 0xA0 to start reading (arbitrary address with known values: all 0xFF)
    write_buf[0] = 0xA0;    
    write(file, write_buf, 1);

    //Reading 1 byte from EEPROM, even though there is a '2'; 2 bytes would be '3'
    read(file, read_buf, 2);

    for (i=1; i<3; i++){
        printf("%X", read_buf[i]);
    }
    //Prints out from address 0x04 to 0x05 instead of 0xA0 to 0xA1

    printf("\n");

    }
4

1 に答える 1