I2C SPI USB CAN eSPI Cable Testing View All Videos Quick Start Guides Software Downloads App Notes White Papers User Manuals Knowledge Base Sales Support About Us
Products Blog Sales Support Contact Search
How Can I Change the Response of an I2C Slave Based on what a Master Writes with the Aardvark Software API?
Kathleen Chan

Question from the Customer:

I am trying to use the Aardvark I2C/SPI Host Adapter and Python API to emulate an I2C slave sensor that conditionally changes its response values depending on what the master device writes to it. When modifying the aai2c_slave.py code, I get a message with "error: non-I2C asynchronous message is pending". What does this mean and what might be the cause of this? Do I need to disable and enable the slave every time I set a new slave response? Is there a clock stretching function for the Aardvark adapter configured as a slave device?

Response from Technical Support:

Thank you for your questions! The Aardvark I2C/SPI Host Adapter cannot set the slave response on the fly while asynchronously reading from the master without a handshake mechanism.

Aardvark I2C/SPI Host Adapter as an I2C Master

The Aardvark I2C/SPI Host Adapter as an I2C master supports 1 KHz - 800 KHz. It is not possible to send bytes at a throughput of exactly 1/8 times the bitrate. The I2C protocol requires that 9 bits are sent for every 8 bits of data. There is also a finite time required to set up a byte transmission. In the development of the Aardvark adapter, many optimizations have been employed to decrease this setup time. This allows byte throughput within each transaction to be very close to the theoretical maximum byte throughput of 1/9 the bitrate.

Aardvark API Latency

There is extra overhead introduced by the operating system between calls to the Aardvark Software API. The aa_i2c_write (or aa_i2c_read) call must complete before the next API call. Each time this function is called, a 2 ms round-trip latency is incurred. This is caused by the full-speed USB link between the computer and the Aardvark adapter.

In addition, the target device may require some delay time in order to commit the write to a specific address and before performing the next read for that address. The device datasheet will have the value of this required delay. Furthermore, the OS may add additional delay due to internal overhead. For this revision of the Aardvark adapter and Aardvark API, there is no current solution to the 2 ms delay that is required between write or read operations. Please see the documentation in the Aardvark I2C/SPI Host Adapter User Manual and I2C signaling characteristics for more details.

Promira Serial Platform Latency

The Aardvark adapter uses USB full-speed (12 Mbps); this makes functions a bit slower than other devices. The Promira Serial Platform uses Ethernet and Ethernet over USB which is faster than the Aardvark I2C/SPI Host Adapter and also provides queue functionality. With the queue functionality, multiple commands can be queued up and shifted to the device at once. For the detail about queuing, please check the Section 5.5.3 of the Promira Serial Platform I2C/SPI Active User Manual.

Aardvark API Slave Read

The aa_i2c_slave_read command in the Python API checks for the master's message asynchronously, and therefore there is no need to poll for checking incoming messages indefinitely.

For setting slave response, the aa_i2c_slave_set_response command sends the response set by the slave automatically on the event of contact by master. For more information, please visit section 5.5.4 of the Aardvark I2C/SPI Host Adapter User Manual. When using the Aardvark adapter response, buffer space is 64 bytes. The slave response is set only when master invokes "read from slave" command.

Clock Stretching

The Aardvark adapter supports clock stretching as part of the hardware implementation of the I2C protocol. The Aardvark adapter can stretch the clock as an I2C slave, but there is no software control with the API and GUI. The user cannot instruct the devices to stretch the clock through API as well. Clock stretching in slave mode is controlled by the internal state machine and is usually used as a mechanism for internal buffer management.

We hope this answers your question. Additional resources that you may find helpful include the following: