Fwd: i2c - Smbus protocol - query

28 views
Skip to first unread message

Abhijit Betigeri

unread,
May 20, 2013, 4:59:58 AM5/20/13
to compute...@googlegroups.com

Hi,

Please help me on this:

I am using the i2c smbus protocol..

from main calling in such a way:
for(i=0;i<len+1;i++)
        buf[i] = (char)(i);
     len = i2c_eeprom_smbus(i2cdev,devAddr,offset,buf,len,0,offset);
     break;

int i2c_eeprom_smbus(
    int file, 
    unsigned short deviceAddr, 
    unsigned char offset, 
    char *buf, 
    int len,unsigned char rd_wr,unsigned char cmd)
{
    struct i2c_smbus_ioctl_data smbusp;
    union i2c_smbus_data smdata;
    
   // struct i2c_msg              i2cmsg;
    int                         i;
   //memset(&smbusp,0,sizeof(smbusp));
   smbusp.read_write = rd_wr;
   smbusp.command = cmd;
   smbusp.size = len;
   smbusp.data = &smdata;
   
   smdata.byte = buf;
   smdata.word = buf;
   smdata.block[0] = len;
   
   if((i=ioctl(file, I2C_SMBUS, &smbusp)) < 0)
    {
      perror("ioctl()");
      fprintf(stderr, "ioctl returned %d\n",i);
      return -1;
    }
    return len;
}

How do I populate these structures and unions:  struct i2c_smbus_ioctl_data smbusp;
    union i2c_smbus_data smdata;
    
here smdata has three fields - can u pl explain the significance of each field..

Kindly throw some light on this..

Thanks

Regards,
Abhijit

Tavish Naruka

unread,
May 20, 2013, 5:56:33 AM5/20/13
to compute...@googlegroups.com
Hi

On Mon, May 20, 2013 at 2:29 PM, Abhijit Betigeri <abhijitb...@gmail.com> wrote:

    struct i2c_smbus_ioctl_data smbusp;
    union i2c_smbus_data smdata;
   

   smdata.byte = buf;
   smdata.word = buf;
   smdata.block[0] = len;

How do I populate these structures and unions:  struct i2c_smbus_ioctl_data smbusp;
    union i2c_smbus_data smdata;
    
here smdata has three fields - can u pl explain the significance of each field..



union i2c_smbus_data {
        __u8 byte;
        __u16 word;
        __u8 block[I2C_SMBUS_BLOCK_MAX + 2]; /* block[0] is used for length */
                               /* and one more for user-space compatibility */
};

Union is way to access the same chunk of memory as different types, so these three
types __u8, __u16, __8 array are actually overlapped. See this for a better understanding
http://stackoverflow.com/questions/740577/sizeof-a-union-in-c-c

--
Regards
Tavish Naruka

Abhijit Betigeri

unread,
May 20, 2013, 6:06:06 AM5/20/13
to compute...@googlegroups.com
Ok.. But here in this scenerio what to populate for byte word and block...

Regards,
Abhijit


--
You received this message because you are subscribed to the Google Groups "Computer Club of India" group.
To unsubscribe from this group and stop receiving emails from it, send an email to computerclubi...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Reply all
Reply to author
Forward
0 new messages