2009-05-27 11:38:02     i2c_transfer destroys data to be written

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

2009-05-27 11:38:02     i2c_transfer destroys data to be written

Doug Bailey (UNITED STATES)

Message: 74652   

 

I am making some modifications to u-boot (1.1.6) to be able to inteface to an

I2C based PCA9635 LED driver.  To communicate with the part I make a call to

i2c_write which in turns calls i2c_transfer.

 

I noticed in i2c_transfer function there is a call to memset that destroys the

information that I am trying to write to the I2C device.  I don't see a reason

as to what the memset call does in the first place.  Am I

missing/misinterpreting something?

 

Regards,

Doug Bailey

 

 

FRAGMENTS from i2c.c ********************************************************************

 

static int i2c_transfer(uchar chip, uint addr, int alen, uchar *buffer, int len, u8 flags)

{

    uchar addr_buffer[] = {

        (addr >>  0),

        (addr >>  8),

        (addr >> 16),

    };

    struct i2c_msg msg = {

        .flags = flags | (len >= 0xff ? I2C_M_STOP : 0),

        .buf   = buffer,

        .len   = len,

        .abuf  = addr_buffer,

        .alen  = alen,

    };

    int ret;

 

    memset(buffer, 0xff, len);  /* Why is this here??? */

  

    debugi("chip=0x%x addr=0x%02x alen=%i buf[0]=0x%02x len=%i flags=0x%02x[%s] ",

                   chip, addr, alen, buffer[0], len, flags, (flags & I2C_M_READ ? "rd" : "wr"));

 

 

int i2c_write(uchar chip, uint addr, int alen, uchar *buffer, int len)

{

    return i2c_transfer(chip, addr, alen, buffer, len, 0);

}

 

Code from my LED driver **********************************************

int init_i2c_led(void)

{

    uchar init_stream[25] = {PCA9635_REG_MODE1 | PCA9635_AUTOINC_MASK_ALL, 0,5,

                    0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,

                    0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,

                    0xff,0,

                    5,5,5,5    };

 

    /* Set the registers to an initial state */

    i2c_write(S800I_PCA9635_ADDR, 0, 0, init_stream, 25);

QuoteReplyEditDelete

 

 

2009-05-27 14:36:45     Re: i2c_transfer destroys data to be written

Mike Frysinger (UNITED STATES)

Message: 74660   

 

that should be fixed already in the 2009R1+ release

QuoteReplyEditDelete

 

 

2009-05-27 15:16:58     Re: i2c_transfer destroys data to be written

Doug Bailey (UNITED STATES)

Message: 74666   

 

I see that the memset has been changed to a dmemset which amounts to nothing if not in DEBUG mode. 

 

I still don't see the value to what this does but since I don't usually compile with DEBUG defined, it should not be a problem.

 

 

 

Thanks

 

Doug

Attachments

    Outcomes