Motion driver 6.12 i2c write

By fbutl , 19 April 2017

Hi

In the motion driver there is multiple instances of this type of i2c write:

tmp[0] = 0;
tmp[1] = BIT_STBY_XYZG;
if (i2c_write(st.hw->addr, st.reg->pwr_mgmt_1, 2, tmp))
return -1;

My question is, will my i2c driver send the 2 bytes consecutively to the same register or will it
be 2 separate writes to the register. Just worried the register address will increment after it
receives the first 0x00 tmp reset byte. The if statement is also bit confusing as I can't find
a way for it to ever be true and return -1, or is that the whole point.

Thanks

Regards
Francois

kevinsw

8 years ago

Note: This an I2C thing nothing to do with the the Motion driver per say.
You should study up on how I2C works. I don't have a URL handy, but you can just web search on the subject.

Anyhow to answer your question (if it still helps a year plus later), it will (at least should) be two consecutive writes.
Think of "st.reg->pwr_mgmt_1" as a memory address (happens to be register 0x6B in all cases).

FYI I don't know why the developer(s) chose this overly complex way of representing static constant register definitions.
There is only one or two register definition groups that are different in the entire MPU6050 and MPU6500 register space, easily handled by compile switches; doesn't warrant such a complex register mapping scheme.
I ripped all that junk out and changed them to simple defines I.E:
const uint8_t PWR_MGMT_1 = 0x6B;
Much easier to read and my compiler/link loves me more for it.

phpbb Post ID
36756
phpbb Topic ID
36317