SPI/I2C slave AA_COMMUNICATION_ERROR using an aardvark
You activated an I2C/SPI slave, already received messages from it and now want to deactivate it, but you get a status code AA_COMMUNICATION_ERROR.? This is probably not a bug in your code!
Explanation:
It can happen that a master sends large amounts of data and thereby completely occupies the host PC receive buffer for the Aardvark I2C / SPI host adapter. The communication error means that while the PC was sending the deactivation request to the slave, no acknowledgment was received from the Aardvark adapter.
In most cases the slave was probably disabled. When the Aardvark adapter has deactivated the slave, no further data is sent or received, so the connection/buffer can no longer be fully occupied. A subsequent call to disable the slave should return with no errors.
Possible solutions:
While this is not necessarily a critical issue in your code, there are a number of ways you can improve the situation.
a.) One is to reduce the amount of traffic sent by the master. This requires the ability to reconfigure the offending master device.
b.) Another option is to periodically poll the slave to get pending asynchronous messages. Note that each call to read pending messages can time out up to 500ms. So if there is other time-sensitive code that needs to run concurrently, it's best to use a threading model. (Aardvark adapter API calls are not thread safe, but can be used if wrapped in appropriate thread synchronization calls.)
For the most powerful development environments it is advisable to use two Aardvark adapters. One Aardvark adapter can be configured to receive the asynchronous I2C/SPI slave messages and the other can be used for synchronous I2C/SPI master communication. With this configuration, one thread in the application can tightly loop to process the slave messages and another thread can handle synchronous operations.