Hi,
I am reatively new to I2C, and I am having troubles running the communication protocol with the Labjack T7 Pro. For a student project I am required to read out measurements of a time of flight distance sensor with the T7 over I2C, and interface the T7 via a c++ program. What confuses me is that in all the examples in c++ on reading data from slaves, only the number of bytes to receive is defined but never where to go and read out the data on the slave a.k.a. the register address (from LJM examples in C++: C_C++_LJM_2019-02-20/more/i2c/i2c_eeprom.c). Relevant extracts form the code demonstrationg this read:
const char * I2C_WRITE_NAME = "I2C_DATA_TX"; const char * I2C_READ_NAME = "I2C_DATA_RX";
int numBytes;
char aBytes[32] = {0};
WriteNameOrDie(handle, "I2C_NUM_BYTES_TX", 1); // Set the number of bytes to transmit
WriteNameOrDie(handle, "I2C_NUM_BYTES_RX", 4); // Set the number of bytes to receive
WriteNameByteArrayOrDie(handle, I2C_WRITE_NAME, numBytes, aBytes);
//Bytes to transmit to slave are first sent to Labjack by handle, registername, number of bytes to be transmitted to slave and their values.
//(no slave registers addresses needed of where to write bytes to?)
WriteNameOrDie(handle, "I2C_GO", 1); //make Labjack do the transaction with slave
ReadNameByteArrayOrDie(handle, I2C_READ_NAME, numBytes, aBytes);//read out received data from Labjack
This is confusing to me for the following reasons: a) In the sensor datasheet the register addresses are always given as locations on where to read out the measurements. b) In the Texas instruments tutorial on i2c (http://www.ti.com/lit/an/slva704/slva704.pdf) on page 7 they say these register addresses are required to read out the data.
Would it be possible for someone to point out what I am missing or maybe create a little dummy example on how to perform this action?
Thanks in advance.
Peter
Look at the examples at the bottom of this page:
https://labjack.com/support/datasheets/t-series/digital-io/i2c
With this EEPROM chip, to read 4 bytes you do a 1 tx and 4 rx where the 1 tx is the memory address to start reading from. To write 4 bytes you do a 5 tx where the 1st bytes is the memory address to start writing from.
So with your chip, look at the examples in it's datasheet to see where it expects the memory address to be set. Perhaps it includes the address in 1 packet like the EEPROM example, or perhaps there is a previous I2C write that sets a pointer.
Thanks!