I have a question about return errors. I am using the Aardvark I2C/SPI Host Adapter with Aardvark Software API with a target I2C device. The test setup: sometimes the target device is not available. In that case, a call to aa_i2c_write results in NACK, which is expected. Because the AA_I2C_NO_STOP flag is used, the Aardvark adapter responds to NACK with the call to free the bus, aa_i2c_free_bus().
However, after freeing the bus, the next call of aa_i2c_write() often results with the error -103, AA_I2C_WRITE_ERROR.
I assume there’s an error in our command usage, and there seems to be no option to reset the Aardvark adapter. Can you help us determine the cause of the AA_I2C_WRITE_ERROR, and how to resolve it?
Response from Technical Support:Thanks for your question! We will go over why errors may occur with write and read commands, and go over the details of using a write-read command, aa_i2c_write_read, which we recommend for your setup.
The aa_i2c_write_read API call writes a stream of bytes to the I2C slave device, which is followed by a read from the same slave device. This command is used when the master device sends data and then waits for the target (slave) device to return a value that is related to the data sent.
The aa_i2c_write_read() returns either a status code or an error code.
The aa_i2c_write_read call is a combination of two API calls: aa_i2c_write_ext and aa_i2c_read_ext. Because two calls are used, aa_i2c_write_read() will not release the bus for a long time. Here are instances that cause the bus to not be released:
Here are details about the aa_i2c_write_read call:
int aa_i2c_write_read (Aardvark aardvark,
aa_u16 slave_addr,
AardvarkI2cFlags flags,
aa_u16 out_num_bytes,
const aa_u08 * out_data,
aa_u16 * num_written,
aa_u16 in_num_bytes,
aa_u08 * in_data,
aa_u16 * num_read);
Arguments:
The aa_i2c_write_read command combines the I2C status code from both write and read operations.
Here is an example of reading five bytes from the register address 0x11 :
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