Hmc 5883 compass address.

Hi

I am trying to change a code from HMC6343 to hmc5883. I need the compass address for the following code

//Instruct compass to read echoes
  Wire.beginTransmission(compassAddress);  // transmit to device
  // the address specified in the datasheet is 66 (0x42)
  // but i2c adressing uses the high 7 bits so it's 33
  Wire.write(0x50);                       // Send a "Post Heading Data" (0x50) command to the HMC6343 
  Wire.endTransmission();                 // stop transmitting

  //Wait for readings
  delay(2);                               // datasheet suggests at least 1 ms

  //Request heading reading from compass
  Wire.requestFrom(compassAddress, 2);    // request 2 bytes from slave device #33

What does the data sheet for the HMC5883 say to use?

I cant understand it that’s why I asked for help.

the address specified in the datasheet is 66 (0x42)

The I2C in data sheets can be confusing.

0x42 = 0100 0010b but if this is the 7 bit address then it is 100 0010b and then shifted left to the 8 bit address + R/W register it is 1000 0100x = 0x84.

Then don’t forget the lsb is the r/w bit so clear/set as needed.

Some data sheets get this address already shifted to the high order 7 bits.

I that case its 0x42 and the lsb is the R/W bit.

First try the 0x84 and if doesn’t work then try non-shifted.

You can also use the I2C address finder. http://playground.arduino.cc/Main/I2cScanner

jremington:
You can also use the I2C address finder. http://playground.arduino.cc/Main/I2cScanner

Thanks works great. The address is 0x1E

waltr:

the address specified in the datasheet is 66 (0x42)

The I2C in data sheets can be confusing.

0x42 = 0100 0010b but if this is the 7 bit address then it is 100 0010b and then shifted left to the 8 bit address + R/W register it is 1000 0100x = 0x84.

Then don’t forget the lsb is the r/w bit so clear/set as needed.

Some data sheets get this address already shifted to the high order 7 bits.

I that case its 0x42 and the lsb is the R/W bit.

First try the 0x84 and if doesn’t work then try non-shifted.

Please note this code is for HMC6343 so is the data sheet referred to.

r

I have changed the address codes but I guess this needs changing too

Wire.write(0x50);                       // Send a "Post Heading Data" (0x50) command to the HMC6343

Any ideas please.

Since you determined the I2C base address is 0x1E then you change this to do a write command to the base address.

Ok on that being the other chip. I saw this address in the comments of the code You posted.

The info still applies but for a different address as in the data sheet.