I am using the Aardvark I2C/SPI Host Adapter and Aardvark Software API to program and read an I2C EEPROM device, the AT24C32. This I2C device has a 2-byte address and uses 2-byte data. Is there a way to use your API functions for that? Your API functions are designed for 8-bit data, but this device has a 16-bit address. The programming language I am using is C.
Response from Technical Support:Thanks for your question! The API functions are designed for 8-bit data, but you can easily use them to read/write with 16-bit data. The API functions and an example are described below.
The aa_i2c_write() and aa_i2c_read() functions have the u16 data type for 16-bit addresses.
Reading from the I2C slave device:int aa_i2c_read (Aardvark aardvark,
aa_u16 slave_addr,
AardvarkI2cFlags flags,
aa_u16 num_bytes,
aa_u08 * data_in);
Arguments
aardvark handle of an Aardvark adapter
slave_addr the slave from which to read
flags special operations
num_bytes the number of bytes to read (maximum 65535)
data_in pointer to data
Writing to the I2C slave device:int aa_i2c_write (Aardvark aardvark,
aa_u16 slave_addr,
AardvarkI2cFlags flags,
aa_u16 num_bytes,
const aa_u08 * data_out);
Arguments
aardvark handle of an Aardvark adapter
slave_addr the slave from which to read
flags special operations
num_bytes the number of bytes to write (maximum 65535)
data_out pointer to data
These functions are designed for 8-bit data. However, 16-bit data can be sent byte-by-byte as 2 separate bytes.
Here is an example for using those commands to read/write 16-data data. Please note, this example is pseudo-code, not an actual program.
u08 addr[2];
int addr_byte = 1;
if (addr_t > 255) {
addr[0] = (addr_t >> 8) & 0xff; // upper byte
addr[1] =(addr_t >> 0) & 0xff; // lower byte
addr_byte = 2;
}
else {
addr[0]= addr_t && 0xff;
addr[1] = 0;
addr_byte = 1;
}
aa_i2c_write(handle, device, AA_I2C_NO_STOP, addr_byte, addr);
For more information about API functions, including the special functions of the "flags", please refer to the subsection I2C Interface of the Aardvark I2C/SPI Host Adapter User Manual
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.