ReadI2C() - conceptual question

How am I suppose to ReadI2C() from a sub-address?

Specifically:

I am using a peripheral device with a single address and an array of internal addressable registers that I should be able to individually WriteI2C() and ReadI2C(). I have no problem with WriteI2C() as the function takes first argument as the device address, while the second argument is set to 2. The first byte is interpreted as a sub-address and the second byte is the informaition written into this sub-address.

However, this approach doesn’t work with ReadI2C() as the first transfer becomes the read from the address instead of required selection of a sub-address.

Is this a conceptual problem or I am doing something wrong?

Btw, in order to WriteI2C() correctly you need shift the actuall address right by one bit prior to passing it to the WriteI2C() as the first argument.

Please help with ReadI2C(,)

Thanks,
Vladimir

Vladimir–

I2C is a protocol that is better suited at a lower level because of the variety of implementations that are allowed. It doesn’t really do well for a higher-level abstraction.

The Cypress device supports the funky manipulations that can occur with I2C, but our relatively simple abstraction only supports the most common situations.

In most of our own implementations, we have found it easier to implement the I2C communications within the FPGA than to deal with the Cypress part. There is a lot more flexibility there to support the variety of I2C devices out there.

I see,

I was hoping not to have I2C controller in FPGA as I need it only during initialization…

May I make a suggestion then:

You already have a rudimentary I2C support in okCUsbFrontPanel class via WriteI2C() and ReadI2C() functions requiring three arguments. Why not to introduce an additional argument to these functions that will indicate a sub-address to be used in the current transaction. This fourth argument would be set to 0xffffffff if an I2C register is addressed directly or to a sub-address value if access to an internal register is required. Or you may have two different instances of the function - one as it is now and another one with four parameters.

I am sure that such function will be very helpful to many people.

Vlad

Thanks for the suggestion, Vlad. Can you please make a list of the I2C devices that require sub-address like this?

Such list would be very long…

I am mostly interested in video frame grabbers. Some examples are: ADV7181, ADV7202, SAA7115 and alike…