Using the Aardvark I2C/SPI Host Adapter, how do I perform 7-bit register reads from an I2C slave device?

Question from the Customer:

I just purchased your Aardvark I2C/SPI Host Adapter, and I have a question. I need to read from an I2C device, using Repeated Start Condition and 7 bit addressing.  Does the Aardvark adapter support this?

Response from Technical Support:

Thank you for your question! What you described is often used when performing a "register" read from an I2C slave device, where the register address is written to the slave, and then the data is read.  You can do this using the aa_i2c_write_read command from our free Aardvark Software API. Samples programs are provided with the API, which can be used as is or modified as needed.

This is achieved with two separate API calls, a write and a read.

  • The write sets the flag parameter to AA_I2C_NO_STOP.
  • The read sets this to AA_I2C_NO_FLAGS

An API example that you can use is provided in the i2c_eeprom.c sample program in the "_readMemory()" function. Here is a code snippet from that program:

u08 addr;
u08 data_in[BUFFER_IN_SIZE];aa_i2c_write( handle, device, AA_I2C_NO_STOP, 1, &addr );
aa_i2c_read( handle, device, AA_I2C_NO_FLAGS, length, data_in );

Here is an example that uses the aa_i2c_write_read API function:

u16 num_written, num_read;
aa_i2c_write_read( handle, device, AA_I2C_NO_FLAGS, 1, &addr, &num_written, length, data_in, &num_read );

Additional resources that you may find helpful include the following:

We hope this answers your question. If you have other questions about our host adapters or other Total Phase products, you can contact us and request a demo that applies to your application.

Request a Demo