How Can I Best Use the Aardvark I2C/SPI Host Adapter as an I2C Slave to Realistically Emulate Sensor Readings?

Question from the Customer:

I have an arm-based embedded controller that I use for thermal control when testing microprocessors. The controller communicates with multiple slave I2C temperature sensors including an I2C temperature sensor interface on our DUT (device under test). I would like to simulate this DUT interface with an Aardvark  I2C/SPI Host Adapter in slave mode.  I’ll be running a loop. I need the slave emulator to provide different a different response - different sensor readings - for each loop cycle. How do I make this work?

Response from Technical Support:

Thanks for your question! The I2C master can easily access (write/read) the Aardvark I2C/SPI adapter in slave mode.

 Aardvark I2C/SPI Host Adapter
Figure 1: Aardvark I2C/SPI Host Adapter

The transactions are listed below.

For write:
<START> I2C_SLAVE_ADDRESS_WRITE_COMMAND <ACK> <REGISTER_OFFSET> <ACK> <REGISTER_DATA> <ACK> <STOP>

For read:
<START>I2C_SLAVE_ADDRESS_WRITE_COMMAND<ACK><REGISTER_OFFSET<<ACK> <REPEATED_START> <I2C_SLAVE_ADDRESS_READ_COMMAND> <ACK> <DATA_FROM AARDVARK> <MASTER_NAK> <STOP>

The Aardvark adapter can deliver a single fixed response (up to 64 bytes) in response to the read command from the I2C master device. With a few extra commands using the Aardvark API software, you can have the Aardvark adapter provide a different response for each loop. You will need to run the loop in sync with a handshake; the I2C master device must wait for the Aardvark adapter to receive new data and then respond before sending the next read command. The API function to use is aa_i2c_slave_set_response.  For details about API software, please refer to the API Documentation. Following is summary of running the loop to provide a different reading for each cycle:

  1. Set the Aardvark slave response (data set A).
  2. I2C master reads from Aardvark slave (gets data set A).
  3. Indicate to the Aardvark slave to change the response.
  4. Set the new Aardvark slave response (data set B).
  5. Indicate to the I2C master that the new slave response is ready.
  6. I2C master reads from Aardvark slave (gets data set B).

Repeat steps 3-6 for each subsequent loop cycle. This handshake method is necessary for your setup; otherwise, each read will return the same data pattern, whether or not new data is set in the Aardvark adapter.

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, feel free to email us at sales@totalphase.com, or if you already own one of our devices and have a technical question, please submit a request for technical support.

Leave a Reply