What is the Correct Order of Commands for an XML Script to Control I2C Devices?

A picture of random order of data

Question from the Customer:

I am developing scripts for I2C devices, and I am learning to use the Aardvark I2C/SPI Host Adapter with Control Center Serial Software. I have a question about the XML scripts – is there a required order of the commands in a script?

I have a question about device interaction:

<i2c_write addr="0x59" count="2" radix="16" nostop="0">56 75</i2c_write>

Are there any rules about the sequence of the write addr, count, radix, and nostop commands, or can they be submitted in any order?

Here is my question about configuration:

<configure i2c="1" spi="0" gpio="1" tpower="0" pullups="1" />

Are there any rules about the sequence of the i2c, spi, gpio, tpower, and pullups commands?


Response from Technical Support:

Thanks for your questions! The commands that you are referring to are basic functions. The sequence should not affect executing the scripts as long as the syntax is correct. The following sections show some variations of correct syntax.

Syntax for Attributes

Here is an example of alternate ways to set up the commands in your script.

For example, this sequence of commands,

<i2c_write addr="0x38" count="2" radix="16">01 fc</i2c_write>

will have same effect as the two different sequences shown below:

Example 1:  <i2c_write count="2" radix="16" addr="0x38">01 fc</i2c_write>
Example 2:  <i2c_write count="2" addr="0x38" radix="16" >01 fc</i2c_write>


Syntax for Hardware Attributes

For the hardware configuration, such as I2C=1 SPI=1 GPIO=0, I2C Pullups Enabled and Power Control Enabled, the sequence of the commands should have no effect on executing the script. Here are some examples of various sequences, which will each perform the same functions:

Example 1: <configure i2c="1" spi="1" gpio="0" tpower="1" pullups="1"/>
Example 2: <configure gpio="0" tpower="1" pullups="1" i2c="1" spi="1"/>
Example 3: <configure i2c="1" tpower="1" pullups="1" spi="1" gpio="0"/>
Example 4: <configure tpower="1" pullups="1" spi="1" gpio="0" i2c="1"/>

Examples of More Complex Scripts

We have many articles that provide additional information and examples of using the Aardvark adapter with our software applications.

How Can I Best Use the Aardvark I2C/SPI Host Adapter with an I2C Open Collector Slave Device? describes how to disable pull-up resistors for open collector devices. The script used is similar to the example scripts you included with your questions. It also introduces other Total Phase devices and applications that could be relevant for your projects.

For more information about communicating with and debugging I2C devices, we recommend taking a look at Understanding I2C Communication and How to Debug the I2C Protocol. We also have a video about programming an I2C EEPROM with the Aardvark adapter and the Control Center Serial Software.

Many solutions are provided in our Knowledge Base articles, as well as our Videos.

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.