2011-07-19 06:16:42     I2C Block Read/Write

Document created by Aaronwu Employee on Aug 27, 2013
Version 1Show Document
  • View in full screen mode

2011-07-19 06:16:42     I2C Block Read/Write

gopal krishnan (INDIA)

Message: 102527   


Hi all,


  I'm working with 2010R1 toolchain and distribution in BF527 custom board.


  I'm using below APIs for I2C Read &Write communication from the user space.But it fails simple write&Read    communication itself..Actually I need to transmit 256 bytes block of data to the destination Register without sending stop bit in between.I tried i2c_smbus_read_byte_data,i2c_smbus_write_byte_data in that case its working fine..i2c_smbus_read_block_data,i2c_smbus_write_block_data upto 32bytes its fine..Because it will support upto 32bytes only.


   Method 1:  // write & Read immediately   


                           file = open(filename, O_RDWR);  //I2C driver open      //opened successfully


                                 (ioctl(file, I2C_SLAVE, addr)     //for slave address  //assigned successfully


     unsigned char buf[10], out[10];

     struct i2c_rdwr_ioctl_data i2c_data;

     struct i2c_msg msgs[2];

     out[0] = out[1] = 0;

     buf[0] = Reg;

     buf[1] = Data;


      msgs[0].addr = Dev;

      msgs[0].flags = 0;

      msgs[0].len = 2;

      msgs[0].buf = buf;

      msgs[1].addr =Dev;

      msgs[1].flags = I2C_M_RD;

      msgs[1].len =1;

      msgs[1].buf = out;


      i2c_data.nmsgs = 2;

      i2c_data.msgs = msgs;


                                 if(ioctl(u32_i2c_id, I2C_RDWR, &i2c_data) < 0)     //getting error


     Method 2:


         I tried seperately write nd read that case also failed..but while writing doesnt give any error...


   Method 3:  for Read//          according to my device


     struct i2c_msg msg = { addr, 0, 0, msg_data };


    struct i2c_rdwr_ioctl_data rdwr = { &msg, 1 };


    msg_data[0] = Reg;


    msg.addr = Dev;


    msg.len = 1;


    msg.flags = 0;


     if (ioctl(u32_i2c_id, I2C_RDWR, &rdwr) < 0)


                printf("could not write for read msg\n");      //I m getting error here also




    msg.len = 1;


    msg_data[0] = 0;


    msg.flags = I2C_M_RD;


    if (ioctl(u32_i2c_id, I2C_RDWR, &rdwr) < 0)


  Please could anyone tell whether i have missed out anything and give directions regarding this for transmitting 256 bytes    block of data..


  waiting for your directions....








2011-07-19 06:42:07     Re: I2C Block Read/Write

Aaron Wu (CHINA)

Message: 102529   


In our uClinux trunk we have examples using the I2C from user space, you may take it as reference: user/blkfin-test/twi_lcd-test/twilcd_userspace_test.c. I did not encounter problem by sending data to LCD for display in that way. Do you always get a error or it's not stable? If it's not stable you can check if the lines are pull up properly, if you have too many I2C device on the same bus, if the clock rate you are using is well accpted by your device.




2011-07-19 12:02:48     Re: I2C Block Read/Write

gopal krishnan (INDIA)

Message: 102538   


Very thanks for giving guidance immediately..


.Actually i need to send 256 Bytes of block  data to the Destination Register..


In which way i have to send?






2011-07-19 23:05:37     Re: I2C Block Read/Write

Aaron Wu (CHINA)

Message: 102544   


Yes the SMBUS has a max limit check of 32, You may use the plain read and write system call over the device node, as described in Documentation/i2c/dev-interface. Both rely on the actual implementation of i2c xfer in i2c-bfin-twi.c.




2011-07-19 23:44:43     Re: I2C Block Read/Write

gopal krishnan (INDIA)

Message: 102545   


         Ya of course. First i tried plain Write/Read communication only...in that case also while writing, didnt give any error msg,but while reading gave som junk values nd error..




2011-07-22 05:13:52     Re: I2C Block Read/Write

Aaron Wu (CHINA)

Message: 102615   


Both the read/write call and the smbus interface are based on the actual xfer implementation in blackfin I2C driver, no idea why one fail one sucess, could you post your whole read/write code here? you can also do some further debug into the actual driver code to see what happens and where you get faild with your read/write. If you don't try to read/write up to 256 in a time, but with a smaller length, will it success?