Support Question of the Week: Optimize Communication with an Aardvark I2C/SPI Host Adapter and a Slave Device

Q: I am using the Aardvark I2C/SPI Host Adapter  while testing slave devices. I enable the I2C or SPI slave and start receiving messages. After I disable the slave device, I receive the status code  AA_COMMUNICATION_ERROR. It seems I cannot disable the slave device  - can you advise how to remedy this?

Thanks for your question! The status code AA_COMMUNICATION_ERROR indicates that after the computer sent the disable request to the slave, the computer did not receive an acknowledgment from the Aardvark I2C/SPI Host Adapter. In the scenario you described, the master was probably sending large amounts of data that saturated the host PC receive buffer for the Aardvark I2C/SPI Host Adapter. Most likely the slave was disabled, but the acknowledgement from the Aardvark adapter was not received.

Optimize communications with Aardvark I2C/SPI Host Adapter set up as a Slave Device Figure 1: Aardvark I2C/SPI Host Adapter

If the Aardvark I2C/SPI Host Adapter did disable the slave, there would be no more incoming data to saturate the link. In this case, if you send another call to disable the slave, the slave should return without error.

To improve your setup, following are suggestions to optimize communication with the I2C/SPI slave device.

  • Reduce the amount of traffic that is sent by the master. Note - this requires configuring the offending master device.
  • Regularly poll the slave to obtain pending asynchronous messages that may occur. Note - each call to read pending messages can result in a timeout, possibly up to 500 ms. If your script includes time critical code that must be executed simultaneously, it is best to employ a threading model.  Aardvark API calls alone are not thread-safe, but they can be used when wrapped with appropriate thread synchronization calls.
  • For performance critical development environments,  we advise using two Aardvark I2C/SPI Host Adapters:
    • Set up one Aardvark I2C/SPI Host Adapter to receive the asynchronous I2C/SPI slave messages.
    • Set up the other Aardvark I2C/SPI Host Adapter for synchronous I2C/SPI master communication.
With this setup, one thread in the application can execute a tight loop to process the slave messages and another thread can process the synchronous operations.

For more information about the Aardvark I2C/SPI Host Adapter and other products, please refer to the following:

Aardvark I2C/SPI Host Adapter
Aardvark Adapter User Manual
Total Phase Products
Product Selector Guide

We hope this answers your question. If you have other questions about our host adapters, API and software tools or other Total Phase products, feel free to email us at sales@totalphase.com  or support@totalphase.com.

Leave a Reply