How does one specify a particular register of an I2C device to write to?

I have an HMC6343 tilt-compensated magnetometer & a number of its features require me to write values to specific registers (eg to alter the variation angle you write to registers 0x0D & 0x0C). But how do I do this with the Wire library? The documentation for Wire doesn't mention anything about this.

What command causes it to know that the data is for a specific register?

This was precisely my question. I've worked it out now, after re-reading the datasheet for the HMC6343 again. Turns out you send 0xF1 (which the HMC6343 interprets as the 'Write to EEPROM' command), followed by the address of the register you want to write, followed by the data you want to write to it.

I presume this is pretty standard fair for I2C devices & it would be nice if the Arduino.cc page on the Wire library had a bit more explanation - atm it doesn't really say anything that isn't obvious from the method names & I would be surprised if writing to specific registers of I2C devices wasn't a very common requirement for people using the Wire library.

/* * Set the 'variation angle correction' (magnetic declination), see p8 in datasheet. * At the cathedral in St Andrews on 07/08/2012 this was 3 degrees 16 seconds West * which is -3.2667 decimal degrees, or -33 tenths of a degree, so MSB/LSB in two's * complement is 11111111/11011111. This is written to EEPROM so technically doesn't * need to be done every time if the device isn't moving to a drastically new * location inbetween use. */ byte deviationMSB = B11111111; Wire.beginTransmission(HMC6343_ADDRESS); Wire.write(0xF1); // 'Write to EEPROM' command Wire.write(0x0D); // EEPROM address of deviation angle MSB Wire.write(deviationMSB); Wire.endTransmission();

/* * Set the Heading Infinite Impulse Response (IIR) filter from its default of 0 * to something a bit more than 0. Again, this is EEPROM so shouldn't need re-doing * unless it is explicitly reset at some point. */ Wire.beginTransmission(HMC6343_ADDRESS); Wire.write(0xF1); Wire.write(0x14); // EEPROM address of the Heading IIR filter LSB Wire.write(0x00); // 0 is no filtering, 15 is filtered with 15 previous readings Wire.endTransmission();

/* * Set the HMC6343 to 'upright front' orientation. This is temporary, but can be * written to an EEPROM register if required. */ Wire.beginTransmission(HMC6343_ADDRESS); Wire.write(0x74); Wire.endTransmission();