Image from Gerald Altmann
Question from the Customer:I am using the Aardvark I2C/SPI Host Adapter on an I2C device with multiple registers. The address of the device I need to communicate with is 0xA6. On that device, I will be writing to registers 0xC and 0xD with a sequential write in python. The Aardvark Software API has an aa_i2c_write function, but it only takes 4 arguments: handle, device_address, flags, and value. How do I include the register address of the selected device? I tried shifting the device address by 8 bits and using the OR operation on the register address, but that did not work.
Here is the code I tried using:
aa_i2c_write(LM51772EVM_I2C.handle, ((device_address<<8) | vout_reg), AA_I2C_NO_FLAGS, array('B', [0 & 0xFF]))
What do I need to change to make this work?
Response from Technical Support:Thank you for your question! There is specific information that you need to access a register, which you can obtain from the data sheet of the device. In addition to the API, you can also use Control Center Serial Software to deliver read and write commands to the selected device.
The registers can be accessed using the instruction set/codes provided in your device's data sheet, and following their pattern of sending instructions using their timing diagrams. You can pass the value in the following order:
device address+register address+data byteFor example, to write "01" to register 6 of the component 0x25, you can pass the value as "06 01" to data_out of aa_i2c_write.
In this case, we recommend calling the function as below:
aa_i2c_write(handle, I2C_DEVICE, AA_I2C_NO_FLAGS, 2, <pointer to data>)
For more details, see the instruction aa_i2c_write in Section 5.5.1, I2C Notes of the Aardvark I2C/SPI Host Adapter User Manual.
We also recommend looking at this Knowledge base article that describes how to perform read and write commands using Control Center Serial Software. This GUI provides a live, detailed view of the interactions and verifies the operations before applying the API.
For example, if the data 04 19 is to be written to register at location 0x12, it can be done by sending 12 04 19 in the message window of Control Center Serial Software.
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.