I2C read problem

03 Mar 2010

Hello,

My situation is this. I want to read from device addresss 0x72, register address 0x01 data which is 16 bit long.

It seems that it is not possible to give address and register addres in i2c.read commad. How to do this?

If I use:

        wdata[0] = 0x01;
        i2c.write(addr, wdata, 1);           // Set pointer to location 01h (first echo)
        pc.printf("Data: '%s'\n",i2c.read(addr, wdata, 2))

it doesnt work and with oscilloscope i can see that it really writes 2 times that address.

BR,

-Eric-

03 Mar 2010

Hello,

You may need to specify the register address by i2c.write first.
Then the read can be done.

On addition to that, the return value from i2c.read is an error state. So if you want to monitor the value, you need to access to the array of wdata.

I think following page may help you.

http://mbed.org/users/okano/notebook/i2c-access-examples/


03 Mar 2010

Solution is clear and working now

this

i2c.write(addr, wdata, 1);           // Set pointer to location 01h (first echo)
pc.printf("Data: '%s'\n",i2c.read(addr, wdata, 2))

is replced with this

        cmd[0] = 0x01;
        i2c.write(addr, cmd, 1);
        i2c.read(addr, res, 2);
        pc.printf("Register 0x03 = %x%x\n", res[0],res[1]);

This is not the best solution but works now.