I am using the Aardvark I2C/SPI Host Adapter to read/write to an I2C slave device that has registers with multi-byte addresses. Most of the register addresses are 2 bytes, and some are 3 bytes. The data is also multi-byte. I am trying to create a script in C with the Aardvark Software API.
That should be possible, as the Control Center Serial Software allows me to specify how many bytes to read or write, as well as the size of the register address in bytes. I just need to know how to use the Aardvark Software API to do this.
I see the aa_i2c_read() and aa_i2c_write() functions for specifying an I2C device ID, a register to read from, and the data to return. So far, I figured out how to use them for 1-byte read and write addresses and data, but I have yet to get them to work for multi-byte address and data.
Is there an example of C code that supports multi-byte address and data?
Response from Technical Support:Thank you for your question! We do not have an example available, but we can create a basic script for you to expand for your use. We will provide an overview of what the Aardvark Software API provides, and then show you some guidelines for handling multi-byte transactions.
The Aardvark Software API functions control the Aardvark I2C/SPI Host Adapter, and can be used to write a custom program for your specific requirements. The API supports multiple OS (Windows, Linux, and Mac) and multiple languages (C, Python, Visual Basic, and C#), and includes examples that can be used as is or modified as need.
The example scripts are available in C, Visual Basic, Python, and Aardvark XML batch script code. README.txt files are included in the package to explain each of the examples. Note – the Aardvark API examples work specifically with the Atmel SPI EEPROM AT25080A, which is included in the I2C/SPI Activity Board.
Here is a summary of the Aardvark API examples:
Currently, we do not have multi-byte access examples. However, the example script aai2c_eeprom could be a good starting point for your use. You should be able to use the API to manually pack the register address into the data packet, using C bit shift operators as needed. The datasheet for your I2C component probably specifies the exact bit layout.
Here is a simple script in which the I2C device has a 16-bit address. The aai2c_eeprom example, which was coded for an 8-bit address, was modified for a 16-bit address. To send a 16-bit address, here is how you would use the _writeMemory function:
:::::::
Data_out[0]=(addr >> 8) & 0xff;
Data_out[1]=(addr >> 0) & 0xff;
Data_out[2]=data1; //Actual
:::::::
Here is a snippet of that part of the program:
We hope this answers your questions. 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.