c - Reading / writing from using I2C on Linux -


I am trying to read / write a FM24CL64-GTR FRAM chip Address on the I2C bus, 0b 1010 011 . .

When I'm trying to write 3 bytes (data is 2 bytes + data by one), I get a kernel message ( [12406.360000] i2c-adapter i2c-0: sendbytes : NAK bailout. ), as well as return returns! = 3. See code below:

  #include & lt; Linux / I2C-dev.h> # Include & lt; Fcntl.h & gt; # Include & lt; Unistd.h & gt; # Include & lt; Stdint.h & gt; Int file; Four filenames [20]; Int addr = 0x53; // B 1010111; / * I2C address * / uint16_t dataAddr = 0x1234; Uint8_t val = 0x5c; Uint8_t buf [3]; Sprintf (filename, "/ dev / i2c-% d", 0); If ((File = Open (File Name, O_RDWR)) & lt; 0) Exit (1); If (ioctl (file, I2C_SLAVE, addr) & lt; 0) exit (2); Buf [0] = data-ed & gt; & Gt; 8; Buff [1] = Data Address & amp; 0xff; Buff [2] = VAL; If (write (file, buff, 3)! = 3) exit (3); ...  

However, when I write 2 bytes, then write another byte, I do not get any kernel error, but when I try to read from fram, always me Get back to 0. Code to read from FRAM:

  uint8_t val; If ((File = Open (File Name, O_RDWR)) & lt; 0) Exit (1); If (ioctl (file, I2C_SLAVE, addr) & lt; 0) exit (2); If (write (file, and dataader, 2)! = 2) {exit (3); If (Read (File, & amp; Wall, 1)! = 1) {exit (3);  

No work returns an error value, and I have also tried with it:

  #include & lt; Linux / i2c.h & gt; Struct i2c_rdwr_ioctl_data work_queue; Structure i2c_msg msg [2]; Uint8_t ret Work_queue.nmsgs = 2; Work_queue.msgs = msg; Work_queue.msgs [0] .addr = addr; Work_queue.msgs [0] .len = 2; Work_queue.msgs [0] .flags = 0; Work_queue.msgs [0] .buf = & amp; Dataadder; Work_queue.msgs [1] .addr = addr; Work_queue.msgs [1] .len = 1; Work_queue.msgs [1] .flags = I2C_M_RD; Work_queue.msgs [1] .buf = & amp; Ret; If (ioctl (file, I2C_RDWR, and works_que) & lt; 0) exit (3);  

Whatever is successful, but always returns 0. Does this hardware issue point out or am I doing something wrong?

Is there a FAM 24 CL 64-GTR on Linux on I2C, and what will be the API? Any link can be useful.

The NAC was a big signal: the lipprotect pin was pulled out, and it should be run on the ground. After that, writing a single address followed by data-bytes is successful (first code section).

The address can be written before reading (by writing)), and then sequential data can be read from the address beginning with that address.


Comments