Other Parts Discussed in Thread: HALCOGEN
Hello!
I have question about working with I2C communication (code).
I was looking the example and I've tried to write my own code.
My slave address is 0x29 and before I can even go into reading I need to set up registers: ATIME, WTIME, ENABLE, CONTROL, CONFIG of the sensor (TCS34725).
So I've done this:
i2cSetSlaveAdd (i2cREG1, 0x29);
i2cSetDirection (i2cREG1, I2C_TRANSMITTER);
for (repeat = 0; repeat < 2; ++repeat) {
i2cSetCount (i2cREG1, 2);
i2cSetMode (i2cREG1, I2C_MASTER);
i2cSetStop (i2cREG1);
i2cSetStart (i2cREG1);
i2cSend (i2cREG1, 2, transmit_w_atime);
while (i2cIsBusBusy (i2cREG1))
;
while (!i2cIsStopDetected (i2cREG1))
;
i2cClearSCD (i2cREG1);
for (delay = 0; delay < 210; ++delay)
;
}
This is just a snippet. First time I am communicating to ATIME reg, next for loop I am communicating with WTIME and so on.
In this code I've sent transmit_w_atime [2] = { 0x01, 0xC0 } which are address of ATIME register and second one is what I want to write inside the ATIME register (is this the correct way to do it?)
Questions I additionally have:
- Is there faster way to send data in one go? To communicate with all five registers at once and send appropriate data to each one of them?
- Why do we use for (repeat = 0; repeat < 2; ++repeat) loop?
- When I want to read from a register, how do I specify in i2cReceive () function the register from which I want to read from and in which variable to store my value?
Thanks!
Marc