
We are using Aardvark I2C/SPI Host Adapter to control a bus that has six fan boards with registers on each board. There are many slave devices on the bus. I am looking at the Aardvark Software API code that was previously written and works correctly. However, there is a line of aa_i2c_write() for each slave device. This results in hundreds of repeated lines of code throughout the script, which makes it tedious to review, update, and maintain the script as needed.
To make it more efficient, I am trying to loop the write commands through an array of addresses. The commands used are effectively the same, but now I am receiving error messages instead of data: -9 INVALID DEVICE HANDLE.
Here is a fragment of the original code:

Here is the for loop for replacing the above code:

Here are the results:

I checked for errors after opening power and found that the problem arises in the loop I substituted into the script. My question: Is it possible to loop through an array of addresses without getting an error thrown from the device?
u16 fanAddresses[6] = {0x2E, 0x2F, 0x2C, 0x2D, 0x4C, 0x4D};
Response from Technical Support:Thank you for your question! Depending on the executable code, the processor, the operating system, and hardware, the exact timing of the code execution may be affected when loops are applied instead of separate lines of code. Because of that, we recommend adding a delay to your code.
Here is a summary of how consecutive write and read/write transactions work:
Our recommendation for the described challenge: Add a minimal delay using aa_sleep_ms(n) inside your loop. Note: The value of n to apply in aa_sleep_ms(n) is dependent on the device under test. We suggest starting with 10ms, aa_sleep_ms(10), then reducing the delay for optimal performance.
We hope this answers your question. Additional resources that you may find helpful include the following:
If you want more information, feel free to contact us with your questions, or request a demo that applies to your application.