linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* 8bit i2c register address
@ 2012-09-24 13:58 mahalakshmi.m
  2012-09-27  5:22 ` Hebbar, Gururaja
  0 siblings, 1 reply; 2+ messages in thread
From: mahalakshmi.m @ 2012-09-24 13:58 UTC (permalink / raw)
  To: linux-arm-kernel

 

Hi,

 

I am trying to send 8 bit register address using i2c_transfer.My code is as
follows.

 

static int My_Read(void *dev, u8 reg, u32 len,

                                 u16 *data, u32 endian)

{

        struct i2c_client *client = dev;

        struct i2c_msg msg[2];

        u16 block_data;

        int ret, icnt;

        unsigned char u8_RetryCnt = 0;

 

        msg[0].addr = client->addr;

        msg[0].flags = client->flags & I2C_M_TEN;

        msg[0].len = 2;

        msg[0].buf = (char *)®

 

        msg[1].addr = client->addr;

        msg[1].flags = client->flags & I2C_M_TEN;

        msg[1].flags |= I2C_M_RD;

        msg[1].len = len ;

        msg[1].buf = (char *)data;

 

                ret = i2c_transfer(client->adapter, msg, 2);

}

 

Where the register address " reg"  is for example 0x08. I want to read a
8bit register address 0x08. 

 

My confusion is that since  i2c_msg structure has u16 is it possible to send
0x08.Will I need to send as 0x0008.

 

struct i2c_msg {

  __u16 addr;

  __u16 flags;

#define I2C_M_TEN              0x0010

#define I2C_M_RD               0x0001

#define I2C_M_NOSTART          0x4000

#define I2C_M_REV_DIR_ADDR     0x2000

#define I2C_M_IGNORE_NAK       0x1000

#define I2C_M_NO_RD_ACK               0x0800

#define I2C_M_RECV_LEN         0x0400

  __u16 len;

  __u8 * buf;

};  

 

Kindly provide ur views.

 

Thanks & Regards,

Maha

 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20120924/ddea0d5b/attachment-0001.html>

^ permalink raw reply	[flat|nested] 2+ messages in thread

* 8bit i2c register address
  2012-09-24 13:58 8bit i2c register address mahalakshmi.m
@ 2012-09-27  5:22 ` Hebbar, Gururaja
  0 siblings, 0 replies; 2+ messages in thread
From: Hebbar, Gururaja @ 2012-09-27  5:22 UTC (permalink / raw)
  To: linux-arm-kernel

On Mon, Sep 24, 2012 at 19:28:45, mahalakshmi.m wrote:
>  
> 
> Hi,
> 
>  
> 
> I am trying to send 8 bit register address using i2c_transfer.My code is
> as follows.
> 
>  
> 
> static int My_Read(void *dev, u8 reg, u32 len,
> 
>                                  u16 *data, u32 endian)
> 
> {
> 
>         struct i2c_client *client = dev;
> 
>         struct i2c_msg msg[2];
> 
>         u16 block_data;
> 
>         int ret, icnt;
> 
>         unsigned char u8_RetryCnt = 0;
> 
>  
> 
>         msg[0].addr = client->addr;
> 
>         msg[0].flags = client->flags & I2C_M_TEN;
> 
>         msg[0].len = 2;
> 
>         msg[0].buf = (char *)&reg;

Here len is 2 which means i2c framework will send 2 bytes data from wherever buf is pointing
However in your code, bug points to reg which is char size. So it is sending incorrect data. 
If reg is actually a char size, then set len = 1 and try.

> 
>  
> 
>         msg[1].addr = client->addr;
> 
>         msg[1].flags = client->flags & I2C_M_TEN;
> 
>         msg[1].flags |= I2C_M_RD;
> 
>         msg[1].len = len ;
> 
>         msg[1].buf = (char *)data;
> 
>  
> 
>                 ret = i2c_transfer(client->adapter, msg, 2);
> 
> }
> 
>  
> 
> Where the register address ? reg?  is for example 0x08. I want to read a
> 8bit register address 0x08. 
> 
>  
> 
> My confusion is that since  i2c_msg structure has u16 is it possible to
> send 0x08.Will I need to send as 0x0008.
> 
>  
> 
> struct i2c_msg {
> 
>   __u16 addr;
> 
>   __u16 flags;
> 
> #define I2C_M_TEN              0x0010
> 
> #define I2C_M_RD               0x0001
> 
> #define I2C_M_NOSTART          0x4000
> 
> #define I2C_M_REV_DIR_ADDR     0x2000
> 
> #define I2C_M_IGNORE_NAK       0x1000
> 
> #define I2C_M_NO_RD_ACK               0x0800
> 
> #define I2C_M_RECV_LEN         0x0400
> 
>   __u16 len;
> 
>   __u8 * buf;
> 
> };  
> 
>  
> 
> Kindly provide ur views.
> 
>  
> 
> Thanks & Regards,
> 
> Maha
> 
>  
> 
> 


Regards, 
Gururaja

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2012-09-27  5:22 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-09-24 13:58 8bit i2c register address mahalakshmi.m
2012-09-27  5:22 ` Hebbar, Gururaja

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).